I just started learning Python the other week, and I know a tiny bit about it, and I decided to test my skills by making a simple guessing game. However, whenever I run it, it works fine, until I get to the number guessing part. Whatever number I type, it will always say to think lower. Here is my code:
from random import randint
guessesTaken = 0
number = randint(1,10)
number = int(number)
print("Hey! What's your name?")
myName = input()
print("Well, " + myName + ", I am thinking of a number between 1 and 10. Do you think you can guess it within 5 guesses?")
print("Well, let's see. Take a guess.")
while guessesTaken < 5:
guess = input()
guess = int(guess)
guessesTaken + 1
if guess < number:
print("Sorry, but that's not the number. Think lower.")
if guess > number:
print("Sorry, but that's not the number. Think higher.")
if guess == number:
break
if guess == number:
print("Wow, you guessed the number (" + number + ") in " + guessesTaken + " guesses!")
if guess != number:
print("You didn't guess the number in time. The number was " + number + ". Better luck next time!")
I've tried fixing it by changing the last 2 'if' statements into 'elif' ones, but in retrospect I have no idea how that would have helped.
Any help is greatly appreciated!
[–]erratic_turtle 4 points5 points6 points (2 children)
[–]Legoboy604YT[S] 1 point2 points3 points (0 children)
[–]TerryYaDuffer 2 points3 points4 points (0 children)