Step-by-step explanation:
I'll go through each requirement and give a general explanation as how you would implement each into your program.
1. Allow the user to enter in the type of pizza that they want to order.
For this, we will of course need some way for the user to input text, and unless you're using some module to implement a GUI, you'll likely be using the input function, which looks something like this:
input("prompt message")
and this returns whatever the user inputs, so you'll need to assign this to a variable such as:
pizza = input("put a message here showing pizza options")
and you can modify the string depending on whatever prompt you want. You can also use print statements to put some text before the input prompt, which show the pizza options and their corresponding price, and then the prompt being "which pizza do you want to order" or something along the lines of this.
Lastly, you want to use this input to select a subtotal (not including tip or tax yet), and I would recommend using a dictionary as such:
prices = {"Plain":11.5, "Veggie":12.5, "Pepperoni":13.5}
and then using the user input as the key to assign a price variable, which contains the price as such:
price = prices[pizza]
The only issue with this is if the user input is invalid then this will raise the KeyError since the key won't exist, in which case you can use if statements to check before trying to get the value, but you would also likely want a while loop to continue attempting to get input, until that input is valid ("Plain", "Veggie", or "Pepperoni")
Since tax is not applied on the delivery fee or tip, we can just apply the 6% tax right now, and then add a delivery fee or tip if needed. a 6% increase can be calculated by multiplying the original number, in this case "price" by 1.06
price = price * 1.06
and now we're done for this section so far.
2. Allow the user to enter in whether this was a pickup or a delivery
Since this not only affect the prices, but also what is displayed in the end, it's useful to store whether it's pickup or delivery as a boolean (true or false). We can use an if/elif/else statement to assign a boolean to the variable "isDelivery".
deliveryInput = input("Is this order for delivery [y/n]")
if deliveryInput == "y":
isDelivery = True
address = input("What is the address? ")
elif deliveryInput == "n":
isDelivery = False
else:
# here you can display some message indicating they put invalid input, and either terminate the program or store this in a while loop, since isDelivery needs to be defined for late
on last thing I forgot to mention above, is if the input is indicating they want delivery, then you also add 5 to the price, which is what the line "price += 5" is doing. Also you want to store the address, which is why you have to ask for input in one of the if statements.
3. Allow the user to enter in the amount of tip
We can store the tip in a variable, but we can also just directly add whatever is input to the price. Another thing to note is we want to convert the input, which is a string, into a number. More specifically a float, not an integer since money can have decimals. We can do this by doing the following:
float(input("Tip Amount: "))
This will first take the input of the user, and then pass it into the float class, which will then convert it into a float, and return that float. We can just directly add this to the price.
price += float(input("Tip Amount: "))
4. Calculus total cost and display total cost and delivery address if provided
We already calculated the total cost by just changing the price as the user input the data necessary for the total cost, so we got that covered. The only thing is rounding, which we can do using an f-string. It looks something like this:
print(f"{price:.2f}")
the stuff inside the curly brackets isn't directly treated as text to be displayed, but instead we're telling it to display the price value, rounded to 2 digits. So let's add some text to this besides just the rounded price.
print(f"The total price is ${price:.2f}")
From here, we can use an if statement to check is the order is for delivery or not, and if so, display the address.
if isDelivery:
print(f"The delivery address is: {address}")
the stuff inside the curly brackets as before isn't directly treated as text, but in this case literal, as in the value of the variable, so the output of this print statement will vary depending on the input, which is then assigned to the address variable.
That's pretty much it in terms of the program, just make sure to add relevant comments, as well as tweaking anything as necessary (in the image it has 1 and 2 as the options instead of y and n, which you can change by just replacing them accordingly, and same thing with the pizza input.