Python Forum
I wrote a code but it does not work out as expected
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
I wrote a code but it does not work out as expected
#1
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!
Reply
#2
Please, show your code
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#3
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  my simple code wont work! help! simon12323121 2 2,031 Sep-05-2021, 09:06 AM
Last Post: naughtyCat
  My code does not work as expected (pygame) rohes_kaugummi 1 1,576 Aug-26-2021, 03:13 PM
Last Post: deanhystad
  A program for backing up documents (doesnt work(code is inside)) Richard_SS 4 3,423 Jun-05-2019, 03:47 PM
Last Post: heiner55
  I Can't Get This Sorting Function In This LinkedList Code To Work JayJayOi 10 7,931 Jan-11-2018, 01:14 AM
Last Post: JayJayOi
  Need help with getting this voting eligiblity code to work Beastly 1 2,526 Aug-16-2017, 03:46 PM
Last Post: ichabod801
  Why can't this code work. sexualpanda 2 3,425 Feb-06-2017, 04:03 PM
Last Post: ichabod801

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020