Help with "Guess the number" script

Larry Hudson orgnut at yahoo.com
Sun Mar 2 02:38:08 EST 2014


On 03/01/2014 05:11 PM, Scott W Dunning wrote:
>
> 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.
>

Another 'problem' is what you failed to mention in your post, but is apparent from the 
instructions that you posted -- this assignment is NOT the complete program, just the beginning 
of one.  Your instructor obviously wants you to work on (and understand) this program fragment 
before continuing with the rest of it.

      -=- Larry -=-




More information about the Python-list mailing list