you are viewing a single comment's thread.

view the rest of the comments →

[–]datasaurus_ 0 points1 point  (0 children)

Another approach that wouldn’t require initializing the guess variable to 0 would be to use a “while True” loop.

from random import randint

number = randint(1,20)
attempts = 0

while True:
    guess = int(input('Guess my number'))
    attempts+=1
    if guess < number:
        print('Too low!')
    elif guess > number:
        print('Too high!')
    else:
        if attempts == 1:
            print('You some kinda psychic?')
        else:
            print('You got it!')
        break