Write a Python program to find the string similarity between two given strings
Program:-
str1 = input("Enter String 1 \n") str2 = input("Enter String 2 \n") if len(str2) < len(str1): short = len(str2) long = len(str1) else: short = len(str1) long = len(str2) matchCnt = 0 for i in range(short): if str1[i] == str2[i]: matchCnt += 1 print("Similarity between two said strings:") print(matchCnt/long)
Output:-
Enter String 1
Python Exercises
Enter String 2
Python Exercises
Similarity between two said strings:
1.0
Enter String 1
Python Exercises
Enter String 2
Python Exercise
Similarity between two said strings: