import random
z = random.randint(1,10)
guess = input("Enter a guess 1-10: ")
guess = int(guess)
if (guess > z):
print("To high, try again!")
guesshighs = input("Last try, enter a number 1-10: ")
guesshighs = int(guesshighs)
if (guesshighs > z):
print("Damn it! You were to high again! The answer was, " + z )
elif (guesshighs < z):
print("Nice try but you were to small! The answer was, " + z)
else:
print("Nice you got it!")
elif (guess < z):
print("To small, try again!")
guesssmallh = input("Last try, enter a number 1-10: ")
guesssmallh = int(guesssmallh)
if (guesssmallh < z):
print("Almost but you were to small! The number was, " + z)
elif (guesssmallh > z):
print("Soooo close but you were to high! The number was, " + z)
else:
print("Nice one you did it!")
else:
print("Nice you guessed correct!")
It's a random number guesser game. When you pick a number and it says it's too small or to big and get the number wrong again after the first try it gives an error instead of saying nice try but the answer was (ANSWER).
y.luis.rojo
1,8554 gold badges24 silver badges44 bronze badges
-
Welcome to stack overflow! Unfortunately, this question is not detailed enough to give you any meaningful help. Please edit your question to include a minimal reproducible example for the issue, including sample input, preferred output, and code for what you've tried so far. Also, since you have an error, please include the full error traceback in the text of the question.E. Zeytinci– E. Zeytinci2020年01月07日 18:27:40 +00:00Commented Jan 7, 2020 at 18:27
1 Answer 1
print("Damn it! You were to high again! The answer was, " + z )
Z is a int and you sum it with a string, you can use "," instead of "+"
like this:
import random
z = random.randint(1,10)
guess = input("Enter a guess 1-10: ")
guess = int(guess)
if (guess > z):
print("To high, try again!")
guesshighs = input("Last try, enter a number 1-10: ")
guesshighs = int(guesshighs)
if (guesshighs > z):
print("Damn it! You were to high again! The answer was, " , z )
elif (guesshighs < z):
print("Nice try but you were to small! The answer was, " , z)
else:
print("Nice you got it!")
elif (guess < z):
print("To small, try again!")
guesssmallh = input("Last try, enter a number 1-10: ")
guesssmallh = int(guesssmallh)
if (guesssmallh < z):
print("Almost but you were to small! The number was, " , z)
elif (guesssmallh > z):
print("Soooo close but you were to high! The number was, " , z)
else:
print("Nice one you did it!")
else:
print("Nice you guessed correct!")
Sign up to request clarification or add additional context in comments.
Comments
lang-py