subject

Write a Python program string_functions. py that defines several functions. Each function re-implements Python's built-in string methods.1. my_compare(str1, str2): Takes two strings as parameters (str1, str2) and 
returns a -1 if str1 is alphabetically less than str2, returns a 0 if str1 is alphabetically equal to str2, and returns a 1 if str1 is alphabetically greater than str2. 
2. is_char_in(string, char): Takes a string and a character as parameters and returns True if the character is in the string or False if it is not.3. is_char_not_in(string, char): Takes a string and a character as parameters and returns True if the character is NOT in the string or False if it is.4. my_count(string, char): Takes a string and a character as parameters and returns an integer count for each occurrence of the character. For example, if the function takes in 'abracadabra' and 'a', the function should return 5.5. my_endswith(string, char): Takes a string and a character as parameters and returns True if the character is the last character in the string or False if it is not. For example, if the function takes in 'quartz' and 'z', the function should return True. If the function takes in 'quartz' and 'q', the function should return False.6. my_find(string, char): Takes a string and a character as parameters and returns the first index from the left where the character is found. If it does not find the character, return -1. For example, if the function takes in ‘programming’ and ‘g’, it should return 3. Do not use str. find() for this.7. my_replace(string, char1, char2): Takes a string and two characters (char1 and char2) as parameters and returns a string with all occurrences of char1 replaced by char2. 
For example, if the string is ‘bamboozle’ and char1 is ‘b’ and char2 is ‘t’ then your function should return ‘tamtoozle’.8. my_upper(string): Takes a string as a parameter and returns it as a string in all uppercase. For example, 'victory' would be 'VICTORY'. Hint: Use the ord(c) function to get the ASCII / Unicode code-point. For example, ord('a') returns the integer 97. Use chr(i) function to convert an integer back to a character. For example, chr(97) returns the string 'a'. You cannot use the built-in string function str. upper() for this.9. my_lower(string): Takes a string as a parameter and returns it as a string in all lowercase. Hint: Similar to the previous item, use ord() and chr(). Do not use str. lower() for this. 
Extra Credit (10 points): my_title(string): Takes a string and returns a string with the first character capitalized for every word. For example, if the input to the function is "I like Python a lot", the function should return the string "I Like Python A Lot".Note- You may not use Python's built-in string methods - e. g., str. find(), str. replace(), str. lower(), lstrip(), startswith(), endswith(), join() … - to implement yours. However, you *should* use them to test your functions to see if they produce the same results. You can do this in the main or in another defined function which is called by the main. You can use all other Python functions.

ansver
Answers: 2

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 07:00, ayoismeisalex
Our primary purpouse as electricians is to do wich of the following core concepts? a: install electrical components in a way they can be upgraded b: install electrical equiptment in a way that reduces heat c: install electrical systems in a safe manner d: only b and c
Answers: 1
image
Computers and Technology, 23.06.2019 16:30, isaiahhuettnerowgg8d
What is one reason why indoor air pollution has become an increasing problem.
Answers: 1
image
Computers and Technology, 23.06.2019 22:30, keel5468
You draw two cards from a standard deck of 52 cards, but before you draw the second card, you put the first one back and reshuffle the deck. (a) are the outcomes on the two cards independent? why?
Answers: 3
image
Computers and Technology, 24.06.2019 11:00, iloveballet1857
Each row in a database is a set of unique information called a(n) ? a.) table. b.) record. c.) object. d.) field.
Answers: 2
You know the right answer?
Write a Python program string_functions. py that defines several functions. Each function re-impleme...

Questions in other subjects:

Konu
Mathematics, 28.11.2019 00:31
Konu
Mathematics, 28.11.2019 00:31