CSIS2101_assgn9

.docx

School

Nova Southeastern University *

*We aren’t endorsed by this school

Course

2101

Subject

Computer Science

Date

Jan 9, 2024

Type

docx

Pages

3

Uploaded by the831unit

Report
Assignment 9: Strings Qn.1 ( 35 points ) In Python operation on strings when you use <string>.replace( old substring, new substring ) function it replaces all instances of the old string with the new string. But write your own replace function which takes three arguments the original string and the old sub string and new sub string replace only the second instance of the old substring with the new substring. If the string has no instance or only one instance of the substring return the original string. The method should use the count function to check whether the count of the old substring is more than 1. If less than 2 return the original string or else method should iterate over the string and replace the second instance of the old sub string and replace with the new sub string. The only string function you can use for this replace function is the find function to find the index of the substring. find function can be used more than once. For example The input string is "Mississippi" Sub String to replace is "ss" and new sub string is “zz”, The function should return “Missizzippi” where second instance of ss is replaced with zz. If no instance or 1 instance, return the original string. For example The input string is "Mississippi" Substring to replace is "k" with “kk” return “Mississippi” as there is no “k” in the string. And similarly for example The input string is "Mississippi" Substring to replace is "pp" with the new sub string “qq” then return original string “Mississippi” as there is only one “pp” in the string. If more than two instances found again replace the second instance of the old substring with the new substring. For example The input string is "Mississippi" and substring to replace is "i" with 1 it returns Miss1ssippi. Name the python function that does it as FirstNameFirstAlphabet LastNameLastAlphabet(UpperCase)_replace( Original String, old substring, new substring). So for example your name is John Doe the function should be jE_replace Qn 2. (35 points) Many companies use telephone numbers like 555-GET-FOOD so the number is easier for their customers to remember. On the dial pad the alphabetic letters are mapped to numbers in the following fashion: A B and C – 2 D E and F – 3 G H and I – 4 J K and L – 5 M N and O – 6
P Q R and S – 7 T U and V – 8 W X Y and Z – 9 Write a program that asks the user to enter a 10 character telephone number in the format XXX- XXX-XXXX or XXX XXXXXXX (In both formats with or without the hyphen “-“). You don’t have to validate the format. It can be all alphabets or mixture of alphabet and Numbers. The application should display the telephone number with any alphabetic character that appeared in the original translated into their numeric equivalent. For example if user enters 555-GET-FOOD, the application should display 555-438-3663. Another example is 800 flowers should display 800 3569377 The program should handle upper case and lower case alphabets. The phone number can contain hyphens ( “-“) like in the first example or spaces like in the second example. Name the python function that does it as FirstNameFirstAlphabet LastNameLastAlphabet(UpperCase)_Number_Converter and this function needs to be called from main. Do not use a dictionary or use replace function to do the conversion . Once again iterate over the string. So for example your name is John Doe the program and the function should be jE_Number_Converter. Start with an empty string as the converted number. Go through each character in the old number, if it is an alphabet convert into a number and add it to the converted number or else add the original character to the converted number. You need to please follow this method for conversion. Qn 3. (30 points) Write a program that accepts a sentence as an input and converts each word to pig latin. In this version to convert a word into pig latin, you make the whole sentence upper case and exchange the last letter and first letter of each word and place the letters at the beginning of the word. Then you append the string “2101” to the word. Here is an example: English: I SLEPT MOST OF THE NIGHT. Pig Latin: I2101 TLEPS2101 TOSM2101 FO2101 EHT2101 TIGHN2101 The program should handle upper case and lower case alphabets. Name the python function that does it as FirstNameFirstAlphabet LastNameLastAlphabet(UpperCase)_Pig_Latin and this function needs to be called from main. So for example your name is John Doe the program and the function should be jE_Pig_Latin. Assume there are no punctuations like !, ? comma, period etc in the given sentence.
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help