Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Download lab 4 . py and rename it according to the instructions above. Modify the program by adding the four missing functions. The functions are

Download lab4.py and rename it according to the instructions above.
Modify the program by adding the four missing functions. The functions are described in the grading section below.
If the missing functions are implemented correctly, this output will appear when the user enters how now brown cow for the first string and ow for the second string. Note: Your solution should work for any pair of strings.
output:
Enter a first string: how now brown cow
Enter a second string: ow
String Concatenation Testing
----------------------------
Using built-in +: how now brown cowow
Using concatenation_loop function: how now brown cowow
Using concatenation_recursion function: how now brown cowow
Occurences of Second String in First String Testing
---------------------------------------------------
Using built-in count: 4
Using occurrences_loop function: 4
Using occurrences_recursion function: 4
full code:
### main
def main():
""" This tests the four required functions. Do not change this code. """
print("CSCI 127, Lab 4")
print("---------------")
string_1= input("Enter a first string: ").lower()
string_2= input("Enter a second string: ").lower()
print("
String Concatenation Testing")
print("----------------------------")
print("Using built-in +: ", string_1+ string_2)
print("Using concatenation_loop function: ",\
concatenation_loop(string_1, string_2))
print("Using concatenation_recursion function: ",\
concatenation_recursion(string_1, string_2))
###
print("
Occurences of Second String in First String Testing")
print("---------------------------------------------------")
print("Using built-in count: ", string_1.count(string_2))
print("Using occurrences_loop function: ",\
occurrences_loop(string_1, string_2))
print("Using occurrences_recursion function: ",\
occurrences_recursion(string_1, string_2))
# ---------------------------------------
main()
grading:
4 points - A function named concatenation_loop is implemented that has two string parameters. The function must return the concatenation of the two strings using an appropriate loop. You may use the built-in concatenation operator (+) to concatenate a string and a character. However, you may not use it to concatenate two strings.
1 point - A function named concatenation_recursion is implemented that has two string parameters. The function must return the concatenation of the two strings using recursion. You may use the built-in concatenation operator (+) to concatenate a string and a character. However, you may not use it to concatenate two strings. Do not use any loops in the solution.
4 points - A function named occurrences_loop is implemented that has two string parameters. The function must return the number of times that the second string parameter appears in the first using an appropriate loop. The built-in count function may not be used.
1 point - A function named occurrences_recursion is implemented that has two string parameters. The function must return the number of times that the second string parameter appears in the first using recursion. Neither the built-in count function nor any loops may be used.

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_2

Step: 3

blur-text-image_3

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

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2010 Barcelona Spain September 2010 Proceedings Part 2 Lnai 6322

Authors: Jose L. Balcazar ,Francesco Bonchi ,Aristides Gionis ,Michele Sebag

2010th Edition

364215882X, 978-3642158827

More Books

Students also viewed these Databases questions