I need help with my python program Design a program to take

I need help with my python program!!!!

Design a program to take two strings as input, and you will compare the two strings, character by character. You need to count the number of occurrences where the characters in the two strings match, and you will output the percentage of matching characters between the two strings.

If the two strings are not the same length, then they are not matching for those extra characters. For example, Jennifer and Jen match on 37.5% of the characters.

Your program must have a main() function, and you must have these functions: get_user_input(), percent_matching(), and num_matching_chars().

Solution

def get_user_input():
   print \'Enter first string: \'
   str1 = raw_input();
   print \'Enter second string: \'
   str2 = raw_input();
   return [str1,str2];

def num_matching_chars( str1, str2 ):
   minSize = min( len(str1), len(str2) );
   commonChars = 0;
   for i in range(minSize):
       if( str1[i] == str2[i] ):
           commonChars = commonChars + 1;
   return commonChars;

def percent_matching( str1, str2 ):
   maxCharacter = max( len(str1), len(str2) );
   commonChars = num_matching_chars( str1, str2 );
   return (commonChars*100.0)/maxCharacter;

def main():
   [str1, str2] = get_user_input();
   a = percent_matching( str1, str2 );
   print str1,\'and\',str2,\'match on\',str(a)+\'%\',\'of the characters\';

main();

I need help with my python program!!!! Design a program to take two strings as input, and you will compare the two strings, character by character. You need to

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site