Python Forum

Full Version: I wrote a code but it does not work out as expected
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I am really new to python, I just studied for a few days.

The home work is:
You display 3 ticket types, cheap, medium, and expensive (each is given a price, e. g,
cheap = 500,
medium = 700,
expensive = 1000
Then, entertainment is given
entertainment = 100
wifi is given too,
wifi = 200

then, you give 5 options: 1)add entertainment, 2)add wifi, 3)remove entertainment, 4)remove wifi,5)finalize price. UNTIL the user chooses 5, the options will continue to pop up, it means to return to the menu, but without resetting the menu, means, if you choose 1, then you can continue to choose 2, and continue to 3, and continue to 4. And so on.
The task here is that, you must allow user to input one type of ticket, then choose add 1) or/and 2), remove 1) or/and remove 2), then whatever the user chooses, for example, 1-2-3-4, or 1-2-3, or 1-3, or 2-4, or 1, or 2, or 1-2, then if he chooses 5) which is to finalize the price, the results must be correct.

What I HAVE done is to create a while loop for the options menu, but I dont see how to jump out the loop, if I jump out the loop, I dont see how I calculate the price to be specific.
I have changed the variable names here, so anyone can just give me a structure?

I would really appreciate any help.
I dont want the answer to my homework directly, however I am really new, so I do want to know how all these work with clear examples. Thanks a lot guys!
Please, show your code
Quote:What I HAVE done is to create a while loop for the options menu, but I dont see how to jump out the loop, if I jump out the loop, I dont see how I calculate the price to be specific.
I have changed the variable names here, so anyone can just give me a structure?

You need the following:
1) Create a variable to keep track of the running total, then change that variable depending on the options they select.
2) Use Google and search 'how to exit a while loop in Python' (I'm telling you to use Google because then in future you won't need to ask).

Put simply, each menu option the user chooses, you need to alter a variable to keep a running total of what the current price would be, then when you break out of the while loop you can print the value of the variable.

Hope this helps and as said before, show your code.