Python Forum
I don't know if it's my error or Python error
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
Reply
#12
Ops, you are right:

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


Possibly Related Threads…
Thread Author Replies Views Last Post
  python error buraq1 3 1,613 Oct-28-2024, 10:23 PM
Last Post: bowlofred
  python error otai1 1 598 Aug-22-2024, 09:24 AM
Last Post: DeaD_EyE
  Python error - how do I fix it? gregaryb 5 1,736 Aug-14-2024, 05:26 PM
Last Post: snippsat
  Error Calculating Circle Area in Python aaronramsdale 1 988 Jun-04-2024, 07:57 AM
Last Post: Pedroski55
  Error on first Python launch garryp4 5 3,873 May-07-2024, 03:56 PM
Last Post: deanhystad
  QGIS 3.34 Python Error paskiller 2 2,123 Nov-13-2023, 06:20 PM
Last Post: buran
  Python error on mentioned Arduino port name dghosal 5 2,203 Aug-22-2023, 04:54 PM
Last Post: deanhystad
  Code error from Fundamentals of Python Programming van Richard L. Halterman Heidi 12 3,782 Jul-25-2023, 10:32 PM
Last Post: Skaperen
Thumbs Down Python Error MahendraYadav 0 685 Jul-21-2023, 05:07 PM
Last Post: MahendraYadav
  Syntax error while executing the Python code in Linux DivAsh 8 5,014 Jul-19-2023, 06:27 PM
Last Post: Lahearle

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020