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


Groups > comp.lang.python > #54166

Re: Need help to sort out the below code...

From John Gordon <gordon@panix.com>
Newsgroups comp.lang.python
Subject Re: Need help to sort out the below code...
Date 2013-09-14 14:42 +0000
Organization PANIX Public Access Internet and UNIX, NYC
Message-ID <l11slb$ekd$1@reader1.panix.com> (permalink)
References <9f6d4a88-4ae4-4e61-9f73-c074ec3f487f@googlegroups.com>

Show all headers | View raw


In <9f6d4a88-4ae4-4e61-9f73-c074ec3f487f@googlegroups.com> mnishpsyched <mnish1984@gmail.com> writes:

> print """
> Please select from the following menu:
> 1. pizza
> 2. steak
> 3. pasta
> 4. burger
> type in any number from above for selection..
> """

> pz = raw_input()
> pz = int(pz)

> st = raw_input()
> st = int(st)

> ps = raw_input()
> ps = int(ps)

> bg = raw_input()
> bg = int(bg)

> but my program doesn't output the selection once i type in any number
> from the list..Please help me to sort it out...

That's because you're calling raw_input() four times, thus the user must
type in a number four times.

You probably want something like this:

    user_choice = raw_input()
    user_choice = int(user_choice)

    if user_choice == 1:
        print "You have selected", user_choice, ".pizza"
        ....
        ....
    elif user_choice == 2:
        print "You have selected", st, ".Steak"
        ....
        ....

-- 
John Gordon                   A is for Amy, who fell down the stairs
gordon@panix.com              B is for Basil, assaulted by bears
                                -- Edward Gorey, "The Gashlycrumb Tinies"

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


Thread

Need help to sort out the below code... mnishpsyched <mnish1984@gmail.com> - 2013-09-13 23:34 -0700
  Re: Need help to sort out the below code... Terry Reedy <tjreedy@udel.edu> - 2013-09-14 03:50 -0400
  Re: Need help to sort out the below code... Jugurtha Hadjar <jugurtha.hadjar@gmail.com> - 2013-09-14 09:38 +0100
  Re: Need help to sort out the below code... John Gordon <gordon@panix.com> - 2013-09-14 14:42 +0000

csiph-web