Re: loops

Discussion in 'Python' started by Mitya Sirenef, Dec 2, 2012.

  1. On 12/02/2012 04:39 PM, Verde Denim wrote:
    > I'm just getting into py coding, and have come across an oddity in a py
    > book - while loops that don't work as expected...
    >
    > import random
    >
    > MIN = 1
    > MAX = 6
    >
    > def main():
    > again = 'y'
    >
    > while again == 'y':
    > print('Rolling...')
    > print('Values are: ')
    > print(random.randint(MIN, MAX))
    > print(random.randint(MIN, MAX))
    >
    > again = input('Roll again? (y = yes): ')
    >
    > main()
    >
    > Produces -
    > python dice_roll.py
    > Rolling...
    > Values are:
    > 5
    > 4
    > Roll again? (y = yes): y
    > Traceback (most recent call last):
    > File "dice_roll.py", line 17, in <module>
    > main()
    > File "dice_roll.py", line 15, in main
    > again = input('Roll again? (y = yes): ')
    > File "<string>", line 1, in <module>
    > NameError: name 'y' is not defined
    >
    > This same loop structure appears in many places in this book "Starting
    > out with Python, 2nd ed, Tony Gaddis), and they all yield the same
    > error. Is there something I'm missing here?
    >
    > Thanks for the input...


    I believe that should be raw_input, not input . input() evaluates user's
    input
    in local scope. -m
     
    Mitya Sirenef, Dec 2, 2012
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. eismaus4

    to many FOR loops?

    eismaus4, Apr 27, 2004, in forum: VHDL
    Replies:
    1
    Views:
    695
  2. Jeremy Morton

    Perl loops should use break, not last

    Jeremy Morton, Jan 29, 2005, in forum: Perl
    Replies:
    1
    Views:
    5,167
    Big and Blue
    Jan 30, 2005
  3. Multiple For Loops?

    , Feb 22, 2006, in forum: VHDL
    Replies:
    1
    Views:
    481
    john Doef
    Feb 22, 2006
  4. =?Utf-8?B?Um9iIE8nQ29w?=

    RedirectFromLoginPage and loops

    =?Utf-8?B?Um9iIE8nQ29w?=, Oct 25, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    415
    =?Utf-8?B?Um9iIE8nQ29w?=
    Oct 25, 2004
  5. Me
    Replies:
    2
    Views:
    255
Loading...

Share This Page