Help with "Guess the number" script
Scott W Dunning
swdunning at cox.net
Sat Mar 1 20:11:07 EST 2014
On Mar 1, 2014, at 11:03 AM, Susan Aldridge <susanaldridge555 at gmail.com> wrote:
> 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)
Thanks Susan! The only problem is he wants us to do it without loops because we haven’t learned them yet. I need to use the variables and function names that he’s given as well. I think I can make sense of what you wrote though so that should help me a bit.
More information about the Python-list
mailing list