In: Computer Science
I keep getting minor errors I can't figure out and I don't know
how to convert decimal .10 to percentage 10%
either.
With these functions defined now expand the program for a company
who gives discounts on items bought in bulk.
Create a main function and inside of it ask the user how many
different items they are buying.
For each item have the user input a price and quantity, validating
them with the functions that you wrote.
Use your discount function to find the discount for each item's
quantity and calculate the discounted price.
Print the discounted price in $9,999.99 format
Sum the discounted totals for all items and display this grand
total at the end.
Print the percentages in 99.9% format.
In addition to summing the discounted totals, also sum the
un-discounted totals.
At the end display both of these values and then calculate and
print the overall percentage saved in 99.9% format.
def discount ():
discount = 0.00
if quantity >= 0 and quantity <= 19 :
discount = 0.00
if quantity >= 20 and quantity >= 49 :
discount = 0.05
if quantity >= 50 and quantity <= 99 :
discount = 0.08
if quantity >= 100 :
discount = 0.10
return discount
# user input quantity
def quantity ():
quantity = 0
quantity = int (input ('What is the quantity? '))
while quantity < 1 or quantity > 2000 :
print ('Error, Please enter a quantity between 1 and 2000.')
quantity = int (input ('What is the quantity? '))
return quantity
# user input price
def price ():
price = 0.0
price = float (input ('What is the price? '))
while price < 0.0 :
print ('Error, the price must be greater than $0.00')
price = float (input ('What is the price? '))
return price
# main
def main ():
for i in range (items)
items = int (input ('How many different items are you purchasing?
'))
quantity ()
discount ()
price ()
Total_price = sum (price)
Total_discount = sum (discount)
Discounted_price = price - (price * discount)
Total_Discounted_price = Total_price - (Total_price *
Total_discount)
print ('For item ',i +1,,' ' Discounted_price, ' with a ',
discount, format (.2f, sep=''))
print ('Total order is ', Total_Discounted_price, ' with a ',
Total_discount, format (.2f, sep=''))
#initiate
main ()
def discount (q):
d = 0.00
if q >= 0 and q <= 19 :
d = 0.00
if q >= 20 and q >= 49 :
d = 0.05
if q >= 50 and q <= 99 :
d = 0.08
if q >= 100 :
d = 0.10
return d
# user input quantity
def quantity ():
q = 0
q = int (input ('What is the quantity? '))
while q < 1 or q > 2000 :
print ('Error, Please enter a quantity between 1 and 2000.')
q = int (input ('What is the quantity? '))
return q
# user input price
def price ():
p = 0.0
p = float (input ('What is the price? '))
while p < 0.0 :
print ('Error, the price must be greater than $0.00')
p = float (input ('What is the price? '))
return p
# main
def main ():
items = int (input ('How many different items are you purchasing?
'))
for i in range(items):
q=quantity()
d=discount(q)
p=price()
Total_price =p*q
Total_discount = d*Total_price
Discounted_price = p - (p * d)
Total_Discounted_price = Total_price - ( Total_discount)
print ('For item ',i +1,' ' ,Discounted_price, ' with a discount',
round(d,2))
print ('Total order is ', Total_Discounted_price, ' with a
discount', round(Total_discount,2))
#initiate
main ()
Screenshots:
The code is edited and the errors are removed.
Please follow the output attached below for reference and proper indentation.