After the first run of the program(when i input the choice) the main function starts automatically again , i want to make it so that it doesnot start automatically ,instead ask if u want to run the program again or exit the program , if i chose to run the program the main() function starts again else the program ends.
file=open("nomobile.txt","w")
text=" If The worLd was Ending , yOU WIll come over right, u will come over and stay the 9it"
file.write(text)
file=open("nomobile.txt",'r')
characters=file.read()
vowels=0
consonants=0
uppercase=0
lowercase=0
for ch in characters:
if ch.islower():
lowercase+=1
elif ch.isupper():
uppercase+=1
ch=ch.lower()
if ch in "aeiou":
vowels+=1
elif ch in "bcdfghjklmnpqrstvwxyz":
consonants+=1
file.close()
def main():
while True:
print("What do you want to know about?")
print("Press 1 to know about uppercase letters")
print("Press 2 to know about lowercase letters")
print("Press 3 to know about vowels")
print("Press 4 to know about consonants")
print("Press 5 to know about all of them at once")
choice=int(input("Press number:"))
if choice == 1:
print("The number of uppercase letters present are", uppercase)
elif choice == 2:
print("The number of lowercase letters present are", lowercase)
elif choice == 3:
print("The number of vowels present are",vowels)
elif choice == 4:
print("The number of consonants present are",consonants)
elif choice == 5:
print("The number of uppercase letters present are", uppercase)
print("The number of lowercase letters present are", lowercase)
print("The number of vowels present are",vowels)
print("The number of consonants present are",consonants)
else:
break
main()
Aucun commentaire:
Enregistrer un commentaire