Help with "Guess the number" script

Susan Aldridge susanaldridge555 at gmail.com
Sat Mar 1 19:03:25 CET 2014


Try this

def guess1(upLimit = 100):
    import random
    num = random.randint(1,upLimit)
    count = 0
    gotIt = False
    while (not gotIt):
        print('Guess a number between 1 and', upLimit, ':')
        guess= int(input())
        count += 1
        if guess == num:
              print('Congrats! You win')
              gotIt = True
        elif guess < num:
              print('Go up!')
        else:
              print('Guess less')
    print('You got it in ', count, 'guesses.')

guess1(100)



More information about the Python-list mailing list