Complete the function ratio_similarity, which computes the ratio of "similarity" between two non-empty strings. The ratio is computed as follows: 2* (the number of matches of characters) / (total number of characters in both strings) The matches are determined in pairwise fashion. For example, consider the strings abcdef and abdce. The three characters at indexes 0, 1 and 4 match. Therefore, the similarity ratio is 2 * 3/(6+5) = 0.5454.... Examples: Function Call string similarity('abcdef', 'abdce') string similarity('dragon', 'flagon') string similarity('stony', 'stony') string similarity('Stony Brook University', 'WolfieNet Secure'). string_similarity('yabba dabba doo', 'bippity boppity boo') string_similarity('Wolfie the Seawolf', "What's...a Seawolf?") [ ] Return Value 5# Test cases 6 print (string_similarity('abcdef', 7 print (string_similarity('dragon', 0.5454545454545454 'abdce')) 'flagon')) 'stony')) 0.6666666666666666 1.0 0.0 1 def string_similarity (str1, str2): 2 return 'Error' # DELETE THIS LINE and start coding here. 0.058823529411764705 0.4864864864864865 3 # Remember: end all of your functions with a return statement, not a print statement! 4 8 print (string_similarity('stony', 9 print (string_similarity('Stony Brook University', 'WolfieNet Secure'))
Complete the function ratio_similarity, which computes the ratio of "similarity" between two non-empty strings. The ratio is computed as follows: 2* (the number of matches of characters) / (total number of characters in both strings) The matches are determined in pairwise fashion. For example, consider the strings abcdef and abdce. The three characters at indexes 0, 1 and 4 match. Therefore, the similarity ratio is 2 * 3/(6+5) = 0.5454.... Examples: Function Call string similarity('abcdef', 'abdce') string similarity('dragon', 'flagon') string similarity('stony', 'stony') string similarity('Stony Brook University', 'WolfieNet Secure'). string_similarity('yabba dabba doo', 'bippity boppity boo') string_similarity('Wolfie the Seawolf', "What's...a Seawolf?") [ ] Return Value 5# Test cases 6 print (string_similarity('abcdef', 7 print (string_similarity('dragon', 0.5454545454545454 'abdce')) 'flagon')) 'stony')) 0.6666666666666666 1.0 0.0 1 def string_similarity (str1, str2): 2 return 'Error' # DELETE THIS LINE and start coding here. 0.058823529411764705 0.4864864864864865 3 # Remember: end all of your functions with a return statement, not a print statement! 4 8 print (string_similarity('stony', 9 print (string_similarity('Stony Brook University', 'WolfieNet Secure'))
Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
Related questions
Question
![Complete the function ratio_similarity, which computes the ratio of "similarity" between two non-empty strings. The ratio is computed as
follows:
2 (the number of matches of characters) / (total number of characters in both strings)
The matches are determined in pairwise fashion. For example, consider the strings abcdef and abdce. The three characters at indexes 0, 1
and 4 match. Therefore, the similarity ratio is 2 * 3/(6 + 5) = 0.5454 ....
Examples:
Function Call
string_similarity('abcdef',
'abdce')
string_similarity('dragon',
'flagon')
string_similarity('stony', 'stony')
string_similarity('Stony Brook University', 'WolfieNet Secure')
string_similarity('yabba dabba doo', 'bippity boppity boo')
string_similarity('Wolfie the Seawolf', "What's...a Seawolf?")
[ ]
Return Value
3
4
5 # Test cases
6 print (string_similarity('abcdef', 'abdce'))
7 print (string_similarity('dragon' 1 'flagon'))
'stony'))
0.5454545454545454
0.6666666666666666
1.0
0.0
0.058823529411764705
0.4864864864864865
1 def string_similarity (str1, str2):
2
return 'Error' # DELETE THIS LINE and start coding here.
#Remember: end all of your functions with a return statement, not a print statement!
8 print (string_similarity('stony',
9 print (string_similarity('Stony Brook University', 'WolfieNet Secure'))
10 print (string_similarity('yabba dabba doo', 'bippity boppity boo'))
11 print (string_similarity( 'Wolfie the Seawolf', "What's...a Seawolf?"))](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2Fa684ef64-b106-44e3-b477-7930de74cd26%2F8cd8a59b-61a1-4c7f-868c-0471dccc95df%2Fsvn9oh_processed.png&w=3840&q=75)
Transcribed Image Text:Complete the function ratio_similarity, which computes the ratio of "similarity" between two non-empty strings. The ratio is computed as
follows:
2 (the number of matches of characters) / (total number of characters in both strings)
The matches are determined in pairwise fashion. For example, consider the strings abcdef and abdce. The three characters at indexes 0, 1
and 4 match. Therefore, the similarity ratio is 2 * 3/(6 + 5) = 0.5454 ....
Examples:
Function Call
string_similarity('abcdef',
'abdce')
string_similarity('dragon',
'flagon')
string_similarity('stony', 'stony')
string_similarity('Stony Brook University', 'WolfieNet Secure')
string_similarity('yabba dabba doo', 'bippity boppity boo')
string_similarity('Wolfie the Seawolf', "What's...a Seawolf?")
[ ]
Return Value
3
4
5 # Test cases
6 print (string_similarity('abcdef', 'abdce'))
7 print (string_similarity('dragon' 1 'flagon'))
'stony'))
0.5454545454545454
0.6666666666666666
1.0
0.0
0.058823529411764705
0.4864864864864865
1 def string_similarity (str1, str2):
2
return 'Error' # DELETE THIS LINE and start coding here.
#Remember: end all of your functions with a return statement, not a print statement!
8 print (string_similarity('stony',
9 print (string_similarity('Stony Brook University', 'WolfieNet Secure'))
10 print (string_similarity('yabba dabba doo', 'bippity boppity boo'))
11 print (string_similarity( 'Wolfie the Seawolf', "What's...a Seawolf?"))
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 1 images

Recommended textbooks for you

Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON

Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science

Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning

Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON

Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science

Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning

Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning

Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education

Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY