Need help to sort out the below code...

John Gordon gordon at panix.com
Sat Sep 14 10:42:51 EDT 2013


In <9f6d4a88-4ae4-4e61-9f73-c074ec3f487f at googlegroups.com> mnishpsyched <mnish1984 at 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 at panix.com              B is for Basil, assaulted by bears
                                -- Edward Gorey, "The Gashlycrumb Tinies"




More information about the Python-list mailing list