I need help with some python code


Joined
Mar 9, 2022
Messages
1
Reaction score
0
im trying to make a game where you guess a number under a certain amount of guesses, i tried putting in a command to make the game reapet however it just doesnt seem to work i need help with this, here is the code:

import random
rand = random.randint(1, 100)
guess_count = 0
guess_limit = 10
play = True
print(rand)
while play == True:
while guess_count < guess_limit:
guess_count += 1
answer = int(input("please enter a number between 1-100: "))
if answer == rand:
print("you got it in", guess_count, "guess(es)")
break
elif answer > rand:
print("lower than that!: ")
elif answer < rand:
print("higher than that!: ")
play = input("would you like to play again? (Y/N): ")
if play == ("y"):
play = True
elif play == ("n"):
play = False
 
Ad

Advertisements

Joined
Mar 3, 2021
Messages
243
Reaction score
29
The code actually works for me, but try taking out the parenthesis in the two play comparisons at the bottom. Also note that you're doing a case sensitive comparison and checking for lowercase while you're input line asking for input line is suggesting uppercase.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top