1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
NISA [10]
3 years ago
6

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.
Computers and Technology
1 answer:
grigory [225]3 years ago
5 0

Answer:

def my_compare(str1, str2):

   mylist = sorted([str1, str2])

   if str1 == str2:

       return 0

   elif str1 == mylist[0]:

       return -1

   elif str1 == mylist[1]:

       return 1

def is_char_in(string, char):

   if char in string:

       return True

   return False

def is_char_not_in(string, char):

   if char not in string:

       return True

   return False

def my_count(string, char):

   return string.count(char)

def my_endswith(string, char):

   return string.endswith(char)

def my_find(string, char):

   if char in string:

       return string.index(char)

   else:

       return -1

def my_replace(string, char1, char2):

   lst = [i for i in string]

   print(lst)

   for i, v in enumerate(lst):

       if v==char1:

           lst[i] = char2

   return "".join(lst)

Explanation:

Above are defined functions similar to the string built-in functions in python. To use them, type in the function name and pass in the required arguments. Save the file name as "string_functions" with a ".py" file extension and use the functions in other files by importing all the function as "import string_functions" or import individual functions with "from string_function import 'function_name' ".

You might be interested in
In what year did the first ibm personal computer debut
m_a_m_a [10]

Answer:

IBM's own Personal Computer (IBM 5150) was introduced in August 1981, only a year after corporate executives gave the go-ahead to Bill Lowe, the lab director in the company's Boca Raton, Fla., facilities. He set up a task force that developed the proposal for the first IBM PC.

4 0
3 years ago
Charts are often used in _____ to quickly represent data and help the readers understand the data.
ololo11 [35]

Answer:

Explanation down below :)

Explanation:

The answer is reports.. . hope that helped!

4 0
4 years ago
Is B$4 is an example of a relative cell reference?
yawa3891 [41]
Yes it is because B$4<span> instructs Excel to keep the </span>cell reference<span> B4 (absolute). assumptions </span>
5 0
3 years ago
You have been hired to develop the website for a popular speaker. He has asked that you include the PowerPoint slides from his l
amid [387]

The method would you suggest for including the slides on the website are:

  • First one need to Download WOWSlider and then register for it.
  • Then one can make your slider. You need to have some images ready to add to the slideshow that you want to make.
  • Then Export your slider.
  • You also need to add the slider to your own webpage.

<h3>What are the different ways of creating slides?</h3>

PowerPoint are known to be one that gives about different ways to create a presentation.

One can use Blank presentation, one can also used  other Design Template and also From AutoContent Wizard.

Note that in the case above, The method would you suggest for including the slides on the website are:

  • First one need to Download WOWSlider and then register for it.
  • Then one can make your slider. You need to have some images ready to add to the slideshow that you want to make.
  • Then Export your slider.
  • You also need to add the slider to your own webpage.

Learn more about slides from

brainly.com/question/24653274

#SPJ1

6 0
2 years ago
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
Hoochie [10]

Answer:

I suggest a core !3

Explanation:

Its pretty good for beginners

3 0
3 years ago
Other questions:
  • William would like to sort a list of items after the data is already entered.
    9·1 answer
  • How would you display all your photographic work in your résumé, if you have a large volume of work?
    10·1 answer
  • Harmful programs used to disrupt computer operation, gather sensitive information, or gain unauthorized access to computer syste
    7·1 answer
  • Your company has been using Windows workgroups on a server running Windows Server 2016. Due to the rapid growth of the company,
    9·1 answer
  • Consider a planet where everyone belongs to a family of six, every family lives in its own house, each house has a unique addres
    8·1 answer
  • A systems engineer suspects a new type of malware has impacted the company network. Which threat hunting approach does the engin
    7·1 answer
  • A chain of coffee servers is sending a spreadsheet of projected costs and profits to some of its investors. When, Kyle, the admi
    7·1 answer
  • Which of the following is NOT an example of one of the six primary ways businesses use the Internet?
    10·2 answers
  • Unscramble dki-----------------------------------------------------------------------...........
    8·2 answers
  • Need comments added to the following java code:
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!