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. DO NOT USE LIST.DO NOT USE LIST.DO NOT USE LIST.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
Here is the required solution
here is the code
import sys
#function to find tax
def fun(sums):
return sums*6.25/100
#find number of values
length=len(sys.argv)
sums=0
#compute sum
for i in range(1,length):
sums+=float(sys.argv[i])
tax=fun(sums)
#print output
print("Number of items:",length-1)
print("Total of items:$"+str(round(sums,2)))
print("Tax Amount:$"+str(round(tax,2)))
print("Total due:$"+str(round(tax+sums,2)))