[Tutor] Menu not working properly
David Hutto
smokefloat at gmail.com
Mon Aug 2 15:13:34 CEST 2010
On Mon, Aug 2, 2010 at 8:00 AM, Evert Rol <evert.rol at gmail.com> wrote:
>> Hello Evert Rol,
>> Thank you for the menu help, I have completed it with great success... There is 1 more problem I am currently having, and when I fix it my program will be completed. If you are interested in helping me with this last stretch, I will be greatly appreciative.
>>
>> If you respond with a yes. I will go ahead and send my code over and list the problem I am currently having.
>
> Jason, it makes more sense to send this to the full tutor list, not just to me:
Ahhhh ha haha, you hit the wrong 'reply to button'. Stupid newb says what?
there are more people who can and will help you. Unless I've missed a
response to a previous post of yours where people disrecommended your
postings, but that shouldn't happen to quickly.
> Although in general, it's better to try and solve the problem yourself, and ask the tutor list if you're really stuck, either with an error or a concept. And the 'try and solve yourself' step can take one or more days and a lot of Googling, but in the end you learn a lot from it.
> So, depending on your current problem, see if you want to try yourself first, or that you feel you need the input from the list.
> (Code can be included with the mail if short; use something like http://python.pastebin.com/ if lengthly code.)
>
> Good luck,
>
> Evert
>
>
>
>
>
>>
>> -Thank You
>>
>> On Mon, Aug 2, 2010 at 3:35 AM, Evert Rol <evert.rol at gmail.com> wrote:
>> > My problem is choice 3. Exit, if you select no or put an invalid answer... It will run menu1... but then it runs
>> > name = raw_input ("Enter your character name. ")
>> > print "Your character name is:", name
>> >
>> > How can i make it so it prints menu1 like normal... then asks you to enter your selection again?
>> > instead of running the above code.
>>
>> Put it in a loop with the necessary break statements. Something like:
>>
>> while True:
>> print menu1
>> answer = raw_input()
>> if ...:
>> ...
>> break
>> elif ...:
>> ...
>> elif ...:
>> answer = raw_input()
>> if ...:
>> sys.exit()
>> raw_input('character name')
>>
>> Only the first option will break out of the loop to the 'character name' question; the other two options will continue to loop, apart from the point where you exit() the whole program.
>> If you need user input until the correct input has been given, that means you'll have to wrap things in a loop (generally a while loop that you break out of when you received correct input).
>> You could factor out the actual code inside the while loop into a function, which can make the structure clearer.
>>
>>
>> Btw,
>>
>> <snip />
>>
>> > characterChoice = input ("Enter your choice. ")
>>
>> You have input() here, while further down raw_input(). The latter is preferred in Python 2.x. I assume this is just a minor mistake.
>>
>>
>> Evert
>>
>>
>> > print
>> >
>> > if characterChoice == 1:
>> > print """
>> >
>> > *Place Holder*
>> >
>> > """
>> >
>> > elif characterChoice == 2:
>> > print "Currently under construction.\nPlease choose again."
>> > print menu1
>> > elif characterChoice == 3:
>> > endProgram = raw_input ("Do you want to end program? yes or no ")
>> > if endProgram == "yes":
>> > sys.exit(0)
>> > elif endProgram == "no":
>> > print menu1
>> > else:
>> > print "\nInvalid Command:\nSelect from the menu again.\n"
>> > print menu1
>> >
>> > print
>> > name = raw_input ("Enter your character name. ")
>> > print "Your character name is:", name
>> > _______________________________________________
>> > Tutor maillist - Tutor at python.org
>> > To unsubscribe or change subscription options:
>> > http://mail.python.org/mailman/listinfo/tutor
>>
>>
>
> _______________________________________________
> Tutor maillist - Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
More information about the Tutor
mailing list