-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path3.py
69 lines (61 loc) · 2.04 KB
/
3.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
'''
3.a
Write a Python program that accepts a sentence and find the number of words, digits,
uppercase letters and lowercase letters.
3.b
Write a Python program to find the string similarity between two given strings
'''
from difflib import SequenceMatcher
def similarity_ratio_between_two_strings(string1,string2):
print("Entered Strings are:",string1,"and:",string2)
print("Similarity ratio between two strings :", end="")
print(SequenceMatcher(None, string1, string2).ratio())
return
def string_test(s):
d={"UPPER_CASE":0, "LOWER_CASE":0,"DIGITS":0,"WORDCOUNT":0}
upper_case = []
lower_case = []
digits = []
for c in s:
if c.isupper():
d["UPPER_CASE"]+=1
upper_case.append(c)
elif c.islower():
d["LOWER_CASE"]+=1
lower_case.append(c)
elif c.isdigit():
d["DIGITS"]+=1
digits.append(c)
elif c.isspace():
d["WORDCOUNT"]+=1
else:
pass
print ("Entered String : ", s)
print ("No. of Upper case characters : ", d["UPPER_CASE"])
print ("No. of Lower case Characters : ", d["LOWER_CASE"])
print ("No. of digits :", d["DIGITS"])
print ("No. of words : ", d["WORDCOUNT"]+1)
print("Upper case characters",upper_case)
print("Lower case characters",lower_case)
print("DIGITS characters",digits)
return
def main_function():
print("===== Menu ===========")
print("1. String Statistics")
print("2. String Similarity")
print("Enter 1 or 2")
print("===========================")
choice = int(input())
if choice != 1 and choice != 2:
print("Please enter 1 or 2 only")
if choice == 1:
input_str = input("Enter the input string whos statistics you want ")
string_test(input_str)
elif choice == 2:
string1 = input("Enter the first string")
string2 = input("Enter the second string")
similarity_ratio_between_two_strings(string1,string2)
return
if __name__=='__main__':
print(__doc__)
main_function()