Reputation: 1
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).
Upvotes: 0
Views: 27
Reputation: 577
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!")
Upvotes: 1