In: Computer Science
Programming Activity 1(Python)
Utilise a count-based iteration structure that will accepts the data listed below and produce the total purchase amount. Your final report should be similar to the one show below.
Input Data:
Item Description | Item Price |
Salomon Fish | $ 26.97 |
Ribeye Steak | $ 12.98 |
Sweet Corn | $ 4.96 |
Asparagus | $5.92 |
Output:
Item Description Item Price
=================================
Salomon Fish $26.97
Ribeye Steak $ 12.98
Sweet Corn $ 4.96
Asparagus $ 5.92
Your total purchase: $ xx.xx
If you have any doubts, please give me comment...
Code:
item_descs = []
item_prices = []
desc = input("Enter item description(press Enter to exit): ")
total_price = 0
while desc != "":
price = float(input("Enter item price: "))
item_descs.append(desc)
item_prices.append(price)
total_price += price
desc = input("Enter item description(press Enter to exit): ")
print("\n%-15s %s"%("Item Description", "Item Price"))
print("==============================")
for it in range(len(item_descs)):
print("%-15s $ %5.2f"%(item_descs[it], item_prices[it]))
print("Your total purchase: $ %.2f"%total_price)