1

I am trying to make a wheel of fortune game, and trying to get both codes to run simultaneously the first while loop is to check whether it is a vowel or consonant, and the second while loop is to check whether the consonant is already picked previously

if currentguess in vowels:
        consonantcheck = False                
    while consonantcheck == False:
        currentguess = input('Not a consonant, please try again with a consonant: ')
        if currentguess not in vowels:
            consonantcheck = True

if currentguess in addedcons:
    consalreadyadded = False
while consalreadyadded == False:
    currentguess = input('The consonant is already guessed, pick another consonant: ')
    if currentguess not in addedcons:
        consalreadyadded = True 
jackanau
  • 25
  • 3

2 Answers2

1

Instead of having two loops that both are dependent on conditions determined within their individual scopes, you can have one loop that you break out of when a condition is met.

while True:
   my_var = do_something()
   if my_var == 1 or my_var == 2:
       do_something_else()
       break

Matt
  • 380
  • 1
  • 9
0

For the purpose of making two validation checks against the same input you can use if and elif statements in an indefinite while loop and break only when the input passes all validations:

addedcons = set()
while True:
    while True:
        currentguess = input('Enter a consonant: ')
        if currentguess in 'aeiou':
            print('Not a consonant, please try again with a consonant.')
        elif currentguess in addedcons:
            print('The consonant is already guessed, pick another consonant.')
        else:
            addedcons.add(currentguess)
            break
    print('Consonants guessed so far:', ', '.join(sorted(addedcons)))

Demo: https://repl.it/@blhsing/UnwrittenSpanishInteger

blhsing
  • 70,627
  • 6
  • 41
  • 76