0

trying to ask user to play or not but when I type no it repeats anyway regardless

import random

play = True

while play:
  
  secret = random.randint(1,101) 

  while True:
    guess = int(input("Input your guess: "))
    if guess == secret:
      print ("Correct!")
      again = str(input("Do you want to play? (Type Yes or No): "))
      break 
    elif guess < secret:
       print ("Too Low")
       continue
    elif guess > secret:
       print ("Too High")
       continue
      
   

if again == "no" or "No":
   play = False 

I want to be able to type 'yes' and plays the guessing game again and when I type 'no' it stops

  • Welcome to SO. ```if again == "no" or "No":``` doesn't do what you think it does. Please refer to https://stackoverflow.com/questions/15112125/how-to-test-multiple-variables-for-equality-against-a-single-value – ewokx Mar 30 '22 at 00:09
  • After changing the ```if again == ...``` line, you should indent it more to be within the ```while play``` loop so that it changes the ```play``` value to break out of the outter while loop. – ewokx Mar 30 '22 at 00:12
  • @Amadan, that is incorrect. Reading from a file will have newlines, but `input()` strips it off for you. – jasonharper Mar 30 '22 at 00:22
  • Oh, you are right! Learn something every day... Thank you! – Amadan Mar 30 '22 at 00:23

0 Answers0