I would like to write a code using python to differentiate difference between 2 strings
There should be 3 results. Good , Almost good , Bad
i) Good which means second string contains in the first string. Eg: smack and mac
ii) Almost good which means part of second string contained in first string. Eg: Rice and Race. both differ by 1 character.
iii)Bad which means more than 1 character is different compared when 2 strings are compared.
Be aware that:
i) position are also important.
tops and post have same characters, but only in 1st position(o) they are the same. hence, more than 1 difference between 2 strings.
ii) different in length between 2 strings.
duplicate and* cake* should return almost good , expression and press should return good
iii) code should automatically compare strings in lower case.
iv) importing is not allowed
Here’s my algorithm, but i failed to implement a rule at which only 1 character is allowed to be different in order to be categorized as almost good
Sa=input('enter something A: ') Sb=input('enter something B: ') Sc=Sa.lower() Sd=Sb.lower() count = 0 for val in Sc: for char in Sd: if char == val: count = count + 1 if count == 0: print("Bad") elif Sc == Sd: print('Good') else: print('Almost Good')