HW4 Homework 4 Due: 11:00 PM, Saturday, October 16, 2021 Part A: Replace comma(comma.py) Write a function replace_commas(s) that replaces all the occurrences of commas in the string s by space and...

1 answer below »
All the instructions in the pdf attached


HW4 Homework 4 Due: 11:00 PM, Saturday, October 16, 2021 Part A: Replace comma(comma.py) Write a function replace_commas(s) that replaces all the occurrences of commas in the string s by space and returns the new string. Outside the function, ask the user for a string input and invoke replace_commas to replace the commas and then print the returned string. Save the program as comma.py. Sample Program Run Please enter a string with comma: ‘Trinity,College,hartford’ Trinity College hartford Part B: Insert into middle(middle.py) Write a function insert_into_middle(s) that inserts space to the middle of string s and returns the new string if the string has even number of characters otherwise the function returns the same string without insertion. Outside the function, ask user for a string input and then invoke insert_into_middle to insert the space. Finally, print the returned string. Save the program as middle.py. Sample Program Run Please enter a string: ‘TrinityCollege’ Trinity College Sample Program Run Please enter a string: ‘Trinity’ Trinity Part C: Rearrange characters(rearrange.py) Write a function rearrange(s) that rearranges the characters in a string s in such a way that lowercase letters come first. Outside the function, ask user for a string input and then invoke the rearrange(s) function to rearrange the characters. Finally, print the returned string . Save the program as rearrange.py Sample Program Run Please enter a string: ‘TriNity’ riityTN Part D: Count digits(count.py) Write a function count_digits(s) that counts the number of digits in a string s. Outside the function, ask user for a string input and then invoke the count_digits(s) function to count digits. Finally, print the number of digits in the string. Save the program as count.py Sample Program Run Please enter a string: ‘300 Summit St, Hartford, CT 06106’ The string has 8 digits Part E: Remove from first and last(remove.py) Write a function remove(s) that removes the first 3 characters and last 3 characters from string s and returns the new string. Outside the function, ask user for a string input and then invoke the remove(s) function to remove 3 characters from first and last. Finally, print the new string. Save the program as remove.py Sample Program Run Please enter a string: ‘Trinity College’ nity Coll What to hand in Upon completion of your homework, create a folder by your last name, copy your python scripts(comma.py, middle.py, rearrange.py, count.py and remove.py) inside the folder. Then create a zip file(your_last_name.zip) and upload the zip file in the moodle. Plagiarism and academic dishonesty Remember, under any circumstance, you must not copy part or all of another’s work and present it as your own. For more details, read our course policy on plagiarism and academic dishonesty in the course syllabus.
Answered 1 days AfterOct 13, 2021

Answer To: HW4 Homework 4 Due: 11:00 PM, Saturday, October 16, 2021 Part A: Replace comma(comma.py) Write a...

Darshan answered on Oct 15 2021
119 Votes
comma.py
# Write a function replace_commas(s) that replaces all the occurrences of commas in the st
ring s by space and returns the new string. Outside the function, ask the user for a string input and invoke replace_commas to replace the commas and then print the returned string.
def replace_commas(s):
    s = s.replace(",", " ")
    return s
    
    
print("Please enter a string with comma:")
mystring = input()
mystring = replace_commas(mystring)
print(mystring)
count.py
#Write a function count_digits(s) that counts the number of digits in a string s.
def count_digits(s):
    count = 0
    
    for i in s:
        if(i.isdigit()):
            count=count+1
    
    return count
    
    
print("Please enter a string:")
mystring = input()
digit =...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here