In: Computer Science
Write a script called script2-4.py that takes a person's delivery order as inputs, totals all the items and calculates the tax due and the total due. The number of inputs is not known. You can assume that the input is always valid. (i.e no negative numbers or string like "cat"). Use a loop that takes the prices of items as parameters that are floats, counts the number of items, and sums them to find the total. You must also use a function that takes the total of the items as input and returns the tax on the amount of the cart. Use a tax rate of 6.25%. The formula for the tax is total*tax_rate. The total due is total_of_items + tax_rate. DO NOT USE LIST. sys.argv only
Input in the command prompt: python script2-4.py 0.95 0.95 5.95 12.95 2.45 1.45
The output for the input above should be exactly the same as the following:
Number of items: 6
Total of items: $24.70
Tax amount: $ 1.54
Total due: $26.24
Code is Given Below:
====================
#creating list to hold items
items=[]
while(True):
#asking user to enter data
i=float(input("Enter Price: "))
items.append(i)
option=input("Wants to enter more (Y/N): ")
if option=='Y' or option=='y':
continue
else:
break
#calculating tax
def taxCalc(total):
return total*0.0625
count=0
sum=0
#finding total
for item in items:
sum=sum+item
count=count+1
#calculating tax
tax=taxCalc(sum)
total_due=sum+tax
#printing result
print("Number of items:",count)
print("Total of items: ${:.2f}".format(sum))
print("Tax amount: ${:.2f}".format(tax))
print("Total due: ${:.2f}".format(total_due))
Output:
==========
Code Snapshot:
==================