Python Forum

Full Version: I don't know if it's my error or Python error
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
It's doesn't end the loop when I type no or n though after being asked if I'd like to play again
Ops, you are right:

Wrong:
if p.lower == "no" or "n":
Right:
if p.lower() == "no"  or  p.lower() == "n":
# This works!
import random
from random import randint

n = ['no', 'n', 'No', 'N', 'NO']
y = ['yes', 'y', 'Yes', 'Y', 'YES']
x = random.randint(1,100)

print("Guess a number between 1 and 100.")

active = True
while active:
	guess = int(input(""))
	if guess == x:
		print("Congratulations! Would you like to play again?")
		play_again = input("")
		if play_again in n:
			print("Thanks for playing!")
			active = False
		elif play_again in y:
			print("Guess a number between 1 and 100.")
		
		
	elif guess < 1 or guess > 100:
		print("You have to choose a number between 1 and 100.")
		print("Please guess again.")
	elif guess < x:
		print("Please choose a higher number.")
	elif guess > x:
		print("Please choose a smaller number.")
Good work.
Pages: 1 2