Computer Networking: A Top-Down Approach (7th Edition)
Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN: 9780133594140
Author: James Kurose, Keith Ross
Publisher: PEARSON
Bartleby Related Questions 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?"))
expand button
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
Check Mark
Knowledge Booster
Background pattern image
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
Computer Networking: A Top-Down Approach (7th Edi...
Computer Engineering
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:PEARSON
Text book image
Computer Organization and Design MIPS Edition, Fi...
Computer Engineering
ISBN:9780124077263
Author:David A. Patterson, John L. Hennessy
Publisher:Elsevier Science
Text book image
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:9781337569330
Author:Jill West, Tamara Dean, Jean Andrews
Publisher:Cengage Learning
Text book image
Concepts of Database Management
Computer Engineering
ISBN:9781337093422
Author:Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:Cengage Learning
Text book image
Prelude to Programming
Computer Engineering
ISBN:9780133750423
Author:VENIT, Stewart
Publisher:Pearson Education
Text book image
Sc Business Data Communications and Networking, T...
Computer Engineering
ISBN:9781119368830
Author:FITZGERALD
Publisher:WILEY