-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathquote.py
61 lines (60 loc) · 1.95 KB
/
quote.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
def create():
qList=[]
global f_name
f_name=input(" Enter the name of file to create : ")
f=open(f_name+".txt",'w')
print("\tGood to go, file created, Now....")
n=int(input("\tEnter the no. of quotes to add : "))
for i in range(n):
quote=input(' '+str(i+1)+". Enter the quote : ")
qList=qList+['\n'+quote]
f.writelines(qList)
print("\t The quotes have been added")
print("*"*65)
f.close()
def read():
f_name=input("\tEnter the name of file to read : ")
print("\tProcessing...")
print("-"*65,end='')
f=open(f_name+".txt", 'r')
x=f.read()
vowl=0
num=0
upper=0
specialChar=0
for i in x:
if i.lower() in 'aeiou':
vowl+=1
if i.isnumeric():
num+=1
if i.isupper():
upper+=1
if not i.isalnum():
specialChar+=1
f.close()
print(x)
print("*"*65)
print("*\t No. of vowels present :",str(vowl).ljust(22),"*")
print("*\t No. of digits present :",str(num).ljust(22),"*")
print("*\t No. of uppercase letters :",str(upper).ljust(22),"*")
print("*\t No. of special characters :",str(specialChar).ljust(22),"*")
print("*"*65)
choice=0
print("|----------------------EXPERIMENT NO.04-------------------------|")
print("| TEXT FILE HANDLING |")
print("-"*65)
while (choice!='3'):
print(" 1. Create a file and enter quotes")
print(" 2. Read a file and get details")
print(" 3. EXIT")
choice=input("\tEnter your choice(1/2/3) : ")
print("*"*65)
if choice=='1':
create()
elif choice=='2':
read()
elif choice!='1'and choice!='2'and choice!='3':
print("\tWrong input enter again")
choice=int(input("\tEnter your choice(1/2/3) : "))
else :
print("\t\t-->Exiting loop")