74.2k views
0 votes
Compute and print an order from Taco Bell.

a) Create a variable taco and assign it the value 1.30
b) Create a variable burrito and assign it the value 2.50
c) Create a variable nachos and assign it the value 3.35
d) Create a constant variable SALES TAX and assign it the value .0875
e) Calculate the subtotal of an order containing a taco, burrito and nachos.
f) Calculate the tax of that same order.
g) Calculate the total of that order including tax.
h) Use f-string formatting, newline and tabs to precisely match the output
Output Example ORDER:
Taco:
Burrito:
Nachos:
SubTotal:
$1.30
$2.50
$3.35
$7.15
Tax:
Total:
$0.63
$7.78

1 Answer

7 votes

Answer:

Here is the Python program:

taco=1.30

burrito=2.50

nachos=3.35

SALES_TAX=0.0875

subtotal = taco+nachos+burrito

tax=subtotal*SALES_TAX

total = subtotal+tax

print(f"Taco:\t\t${taco}\\Burrito:\t${burrito}\\Nachos:\t\t${nachos}\\SubTotal:\t${subtotal}\\")

print(f'Tax:\t\t${tax:.2f}\\Total:\t\t${total:.2f}')

Step-by-step explanation:

First the variable taco is assigned 1.30 value

Then variable burrito is assigned 2.50 value

Then variable nachos is assigned 3.35 value

Next value of constant variable SALES_TAX is set to 0.0875

Next subtotal of an order is calculated by adding the values of taco, burrito and nachos.

Next tax of the order is computed by multiplying the values of subtotal and SALES_TAX .

Next total of that order including tax is calculated by adding the value of tax to that of subtotal

The last two print statements use f-string formatting to print the output. In the first print statement

print(f"Taco:\t\t${taco}\\Burrito:\t${burrito}\\Nachos:\t\t${nachos}\\SubTotal:\t${subtotal}\\")

\t is used to give tab space

f is used as a start of f-string

\\ is used to add a new line

$ sign is attached to the values of taco, burrito, nachos and subtotal.

The second print statement:

print(f'Tax:\t\t${tax:.2f}\\Total:\t\t${total:.2f}')

{tax:.2f} and {total:.2f} means the values of tax and total variables are displayed up to two decimal place (.2f)

So the output of the above program is:

Taco: $1.3

Burrito: $2.5

Nachos: $3.35

SubTotal: $7.15

Tax: $0.63

Total: $7.78

However this can be written in one statement only

print(f"Taco:\t\t${taco}\\Burrito:\t${burrito}\\Nachos:\t\t${nachos}\\SubTotal:\t${subtotal}\\\\Tax:\t\t${tax:.2f}\\Total:\t\t${total:.2f}")

This single statement will print the above given output.

Compute and print an order from Taco Bell. a) Create a variable taco and assign it-example-1
User JungleMan
by
8.4k points