Using Python: I can't get it to loop and then add the total. Here is my code. What am I doing wrong and how would you code this. see attachemnt
Types of Loop
Loops are the elements of programming in which a part of code is repeated a particular number of times. Loop executes the series of statements many times till the conditional statement becomes false.
Loops
Any task which is repeated more than one time is called a loop. Basically, loops can be divided into three types as while, do-while and for loop. There are so many programming languages like C, C++, JAVA, PYTHON, and many more where looping statements can be used for repetitive execution.
While Loop
Loop is a feature in the programming language. It helps us to execute a set of instructions regularly. The block of code executes until some conditions provided within that Loop are true.
Using Python:
I can't get it to loop and then add the total. Here is my code. What am I doing wrong and how would you code this. see attachemnt
#Create a variable to control the loop.
total_amount = 0
#Calculate a series of price items.
while total_amount != '0':
#Get the input from the user for the price of the ticket.
ticket_price = float(input("Enter the ticket price of the item or zero to quit: "))
#Get the input from the user for the reduced item.
reduced_item = input("Is this item reduced y/n? ")
#Get the input from the user for the taxable item.
tax_item = input("Is this item taxable y/n? ")
#Display the outputs
print("Bill for this item")
print("Original price $", format(ticket_price, ",.2f"), sep="")
#Check the reduced item.
#If item is reduced, then calculate the reduced price.
reduced = (ticket_price *25) / 100
#Display the reduction
print("Reduction during the event $", format(reduced, ",.2f"), sep="")
#Display the outputs for the final price.
final_price = ticket_price - reduced
print("Final price $", format(final_price, ",.2f"), sep="")
#Calculate the sales tax.
tax_item = (final_price * 7) / 100
tax_item = 0
#Display the output.
print("7% Sales tax $", format(tax_item, ",.2f"), sep="")
#Calculate the subtotal.
sub_total = final_price + tax_item
#Display the output
print("Item subtotal $", format(sub_total, ",.2f"), sep="")
#set accumulator to 0.
total = 0.0
total = total + sub_total
#Display the output for all total items if user does not
#want to price another item.
total_amount = input("Enter the ticket price of the item or zero to quit: ")
print("Total amount due $" ,format(total, ",.2f"), sep="")
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 3 images