Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #67399

Re: Help with "Guess the number" script

Subject Re: Help with "Guess the number" script
From Scott W Dunning <swdunning@cox.net>
Date 2014-03-01 18:11 -0700
References <43B63C46-3A2D-4374-8A42-EE931BA9A6C4@cox.net> <mailman.7516.1393691734.18130.python-list@python.org> <YJ7s1n00C3bjUJS01J7tQ2>
Newsgroups comp.lang.python
Message-ID <mailman.7555.1393722671.18130.python-list@python.org> (permalink)

Show all headers | View raw


On Mar 1, 2014, at 11:03 AM, Susan Aldridge <susanaldridge555@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.  

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Re: Help with "Guess the number" script Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2014-03-01 11:35 -0500
  Re: Help with "Guess the number" script Susan Aldridge <susanaldridge555@gmail.com> - 2014-03-01 10:03 -0800
  Re: Help with "Guess the number" script Scott W Dunning <swdunning@cox.net> - 2014-03-01 18:11 -0700
    Re: Help with "Guess the number" script Larry Hudson <orgnut@yahoo.com> - 2014-03-01 23:38 -0800
    Re: Help with "Guess the number" script Scott W Dunning <swdunning@cox.net> - 2014-03-02 18:36 -0700
  Re: Help with "Guess the number" script Chris Angelico <rosuav@gmail.com> - 2014-03-02 12:16 +1100
  Re: Help with "Guess the number" script Scott W Dunning <swdunning@cox.net> - 2014-03-02 18:40 -0700
  Re: Help with "Guess the number" script Scott W Dunning <swdunning@cox.net> - 2014-03-02 20:44 -0700
  Re: Help with "Guess the number" script Ben Finney <ben+python@benfinney.id.au> - 2014-03-03 14:52 +1100
  Re: Help with "Guess the number" script Scott W Dunning <swdunning@cox.net> - 2014-03-02 21:04 -0700
  Re: Help with "Guess the number" script Dave Angel <davea@davea.name> - 2014-03-03 02:10 -0500

csiph-web