Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 I don't know if it's my error or Python error
#11
It's doesn't end the loop when I type no or n though after being asked if I'd like to play again
Quote
#12
Ops, you are right:

Wrong:
if p.lower == "no" or "n":
Right:
if p.lower() == "no"  or  p.lower() == "n":
Quote
#13
# 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.")
Quote
#14
Good work.
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Python Code error Riteshfrancis 2 130 May-21-2020, 06:37 AM
Last Post: Riteshfrancis
  python error gfredrickson 2 142 May-10-2020, 09:37 AM
Last Post: pyzyx3qwerty
  Mysql-Python Connectivity Error aryamanurs 2 163 Apr-29-2020, 02:21 PM
Last Post: aryamanurs
  Python: Call function with variabele? Ending in error. efclem 5 166 Apr-22-2020, 02:35 PM
Last Post: buran
  python-resize-image unicode decode error Pedroski55 3 219 Apr-21-2020, 10:56 AM
Last Post: Pedroski55
  appear fatal error popup for Python 2.7, what to do to Not appear again...? lsepolis123 1 258 Mar-23-2020, 10:44 PM
Last Post: lsepolis123
  Python 3.7, Windows 7, Syntax Error hughdent 1 256 Mar-23-2020, 10:09 AM
Last Post: buran
  Error in Python3.6:free() Corrupted unsorted chunks error sameer_k 2 270 Mar-18-2020, 09:37 AM
Last Post: sameer_k
  Simple python code error cls0724 5 398 Mar-12-2020, 07:45 PM
Last Post: stullis
  Python Type error! SamAnw 4 306 Feb-14-2020, 03:46 PM
Last Post: buran

Forum Jump:


Users browsing this thread: 1 Guest(s)