Dies ist mein erstes Mal auf dieser Website und bin neu in der Programmierung. Ich möchte, dass der Benutzer ein anderes Wort eingeben kann, wenn er "y" sagt. Ab sofort sendet das Programm sie an die während Aussagen. Jeder Rat würde geschätzt werden.Zurück zu meiner if-Anweisung
print('Welcome to Word Madness!!')
vowels = list('aeioyu')
consonants = list('bcdfghjklmnpqrstvwxz')
wordCount = 0
complete = False
while not complete:
mode = input('Would you like to type Vowels, Consonants, or Quit?: ').lower().strip()
print('You chose to enter: ',str(mode))
#When user chooses to quit program will system exit
if mode == 'quit':
print('Sorry to see you go! Come back to Word Madness soon!')
import sys
sys.exit(0)
#If vowels are selected then they will be counted
if mode == 'vowels':
word = input('Please enter your word!')
number_of_vowels = sum(word.count(i) for i in vowels)
print('Your word was : ',word,'Your Vowel count was: ',number_of_vowels)
wordCount = wordCount + 1
choice = input('Do you have another word? Y/N: ').lower().strip()
if choice == 'n':
averageV = int(number_of_vowels // wordCount)
print('Your average number of Vowels was: ',averageV)
print('Thank you for using Word Madness!')
complete = True
else:
mode = 'vowels'
#If consonants are selected then they will be counted
elif mode == 'consonants':
word = input('Please enter your word!')
number_of_consonants = sum(word.count(i) for i in consonants)
print('Your word was : ',word,'Your Consonant count was: ',number_of_consonants)
wordCount = wordCount + 1
choice = input('Do you have another word? Y/N: ').lower().strip()
if choice =='n':
averageC = int(number_of_consonants // wordCount)
print('Your average number of Consonants was: ',averageC)
print('Thank you for using Word Madness!')
complete = True
#If user has no more words to enter then they are given an average
else:
mode == 'consonants'
else:
print('ERROR! INVALID INPUT DETECTED!')
Der Code scheint mir gut. Können Sie stattdessen klarstellen, wonach Sie den Code suchen? – ifconfig
Gibt es hier eine Frage? Es gibt keinerlei klare Problemstellung. –
Ich entschuldige mich. Das Problem ist, dass, wenn der Benutzer "y" eingibt, anstatt zurück zu dem if-Modus == x zu gehen, zu dem while nicht abgeschlossen wird. Wollte wissen, ob es einen Weg für die Benutzereingabe gab, zu dem sie zurückkehrten, als sie Vokal oder Konsonant eingaben, anstatt das Programm neu zu starten. –