Answered step by step
Verified Expert Solution
Link Copied!

Question

00
1 Approved Answer

Hello, I am struggling with understanding how for and while loops work. I'm working on code in class that is building on this area and

Hello, I am struggling with understanding how for and while loops work. I'm working on code in class that is building on this area and need some explanation on how to add these techniques.

The first code we were requested to build was:

Write a Python program in a .py file that includes the following:

  1. The program should track a customer's orders at a restaurant and add the appropriate sales tax to calculate the amount due. Note: AZ Sales Tax is 5.6%. This should be defined as a constant using the decimal version .056.
  2. The order should include four items, an appetizer, an entree, a dessert, and a drink. The program should prompt the user to enter the cost for each item.
  3. The program should thank the customer by name and allow them to add a percentage tip based on the pre-tax order amount.
  4. Finally, the program should display the grade total to be billed to the customer's credit card.

My code looked like this:

# The these lines request the customer inputs that tell was who the customer is as well as the numbers required to calculate the customer's pre-tax meal total name = str(input("Please enter your name: ")) appetizer = float(input("Please enter appetizer total: ")) entree = float(input("Please enter entree total: ")) dessert = float(input("Please enter dessert total: ")) drink = float(input("Please enter drink total: ")) # We calculate the pre-tax meal total meal = float(appetizer+entree+dessert+drink) # We've chosen to have a selection of tip percentages available for the customer's reference and need to calculate it tenPercent = meal * .10 fifteenPercent = meal * .15 twentyPercent = meal * .20 # Our final customer requested input, we ask for a percentage tip from the customer would like to add to their pre-tax total tipRequest = int(input("Thank you {}, for dining with us! Your meal total before tax is: ${}, Please enter the additional percent you would like to tip*: *Tips are not required but always appreciated! 10% is ${} 15% is ${} 20% is ${} ".format(name,round(meal,2),tenPercent,fifteenPercent,twentyPercent))) # We calculate our total with the tip included tipIncluded = float((meal*(tipRequest/100))+ meal) # Our one constant that will not change unless law changes the sales tax tax = float(.056) # We calculate the post tax total now that we have tip determined total = float((((tipIncluded)*tax)+(tipIncluded))) # Our final output will tell the customer exactly what their credit card charge will be as well as round out after tax and tip total similar to out pre-tax meal total print("Your new total of $"+str(round(total,2)),"will be billed to your credit card. Have a great day!")

This is what is required of the new code:

  1. Modify your program to accommodate four different people at the table.
    1. Allow each person to order as many items as they wish. When each person is finished ordering, have them enter an exit code before going to the next patron.
    2. You do not need to repeat back the order at the end, but rather total the amount due for the entire party.
    3. Define constants for three different state tax rates: California (8%), Nevada (6.85%) and Arizona (5.6%) and have the program ask the patrons which state they are in.
    4. Apply the appropriate sales tax rate and give the final amount with an option to tip as before.

Since we only require collecting information from four patrons I imagine we will use a for loop with a range of 4 but, I cannot figure out how this needs to be worked. Additionally, I do not grasp the exit code referenced. Would this be handled in an if statement? Thank you for the help.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions