Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

IN PYTHON Implement your own version of the following string methods In this lab, we will familiarize ourselves with string functions in Python as well

IN PYTHON

Implement your own version of the following string methods

In this lab, we will familiarize ourselves with string functions in Python as well as get practice with function parameters and returning values from a function. As you know, there are many methods that are built into the String data type. Here is an implementation of the count function whose signature is def count(text, aChar). For this lab, you will re-implement the following string methods in your own python program (string_functions.py) (5 points per function) :

cs110upper - Takes an input string as a parameter and returns it as a string in all uppercase. Hint: Use the ord(c) function to get the ASCII value of a character. For example, ord('a') returns the integer 97. You will also need to use the chr(value) function that returns a string of one character whose ASCII code is the integer value. For example, chr(97) returns the string 'a'. You cannot use the built-in string function upper()for this.

cs110lower - Takes an input 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 lower() for this.

cs110rfind - Takes an input string and a character as a parameter and returns the first index from the right where the character is found. The original find method finds the first left index of a substring, not just a character.

cs110compare - Takes two input strings as parameters (str1, str2) and

returns a -1 if str1 is less than str2,

returns a zero if str1 is equal to str2, and

returns a +1 if str1 is greater than str2.

cs110strip - Takes an input string as a parameter and returns the same input string with all the whitespace stripped out from the left and the right

cs110replace - Takes an input string and two characters (char1 and char2) as parameters and returns a string with char1 replaced by char2 in the input string.

cs110lstrip - Takes an input string as a parameter and returns the same input string with the whitespace stripped out from the left side of the string

cs110in - Takes an input string and a search string as a parameter and returns either True or False depending on whether the search string is completely in the input string or not.

cs110notin - Takes an input string and a search string as a parameter and returns True if the search string is NOT in the input string. It returns False otherwise.

cs110capitalize - Takes an input string and returns a string with the first character capitalized for every word. The rest of the characters are in lower case. For example, if the input to the function is "I like Python a lot", the function should return a string that looks like "I Like Python A Lot"

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Put Your Data To Work 52 Tips And Techniques For Effectively Managing Your Database

Authors: Wes Trochlil

1st Edition

0880343079, 978-0880343077

More Books

Students also viewed these Databases questions

Question

How do Excel Pivot Tables handle data from non OLAP databases?

Answered: 1 week ago