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...
icon
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?"))
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
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
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 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)
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
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY