Here, The following code is to count discount according to the number of units entered. I want some suggestions on how to modify the code if the input is entered in decimal(float), not only integers.
def main():
print ('''"Bags Discount Calculator"''')
print ()
numberofbags= int(input ("Enter number of bags purchasd : "))
#Taking input for number of bags
print ()
price=99
print ('Number of units purchased is : ',numberofbags) #output for number of bags
#if elif for counting discount rate according to the number of bags taken in input
if numberofbags<10:
discountRate = 0
print('Discount rate applied is 0%')
elif numberofbags <=19:
discountRate = float(0.20)*price*numberofbags
print('Discount applied is 20%')
elif numberofbags <=49:
discountRate = float(0.30)*price*numberofbags
print('Discount applied is 30%')
elif numberofbags <=69:
discountRate = float(0.35)*price*numberofbags
print('Discount applied is 35%')
elif numberofbags<=99:
discountRate = float(0.40)*price*numberofbags
print('Discount applied is 40%')
elif numberofbags >=100:
discountRate = float(0.50)*price*numberofbags
print('Discount applied is 50%')
else:
print('Enter a correct number')
totalpriceofbags=numberofbags*price
totalafterdiscount=totalpriceofbags-discountRate
saving=totalpriceofbags-totalafterdiscount #Counting the saving
print()
print('Total price of bags without discount is : ',totalpriceofbags,'$')
print ()
print('Total savings due to discount is : ',format(saving, ',.2f'),'$')
print ()
print('The total cost of the purchase is : ',format (totalafterdiscount, ',.2f'),'$')
# End of the main function
main()
Aucun commentaire:
Enregistrer un commentaire