I'm new to python and I'm trying to make a simple Guess the number game, and I'm stuck in an if statement in a while loop. here is the code.
I'm experiencing it at the Your guess it too high and the low one. I tried breaking it, but it simply stops the whole things
def guess_the_number():
    number = random.randrange(20)
    guessesMade = 0
    print('Take a guess')
    guess = input()
    guess = int(guess)
    while guessesMade < 6:
        if guess < number:
            print('Your guess is too low.')
        if guess > number:
            print('Your guess is too high.')
        if guess == number:
            break
    if guess == number:
        print'You got it in', guessesMade, 'guess(es)! Congratulaions!'
    else:
        print'I\'m sorry, the number was', number
                You never increment guessesMade so guessesMade < 6 will always be True. You need to modify this value within your loop. You also need to move your prompt for user input into the loop
while guessesMade < 6:
    guess = int(input('Take a guess'))
    if guess < number:
        print('Your guess is too low.')
        guessesMade += 1
    elif guess > number:
        print('Your guess is too high.')
        guessesMade += 1
    else:
        break
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With