Oct-31-2018, 10:28 PM
So I missed the day of class where they went over rounding and I can't seem to get my code to always round to 2 decimal places.
I'm new to python and coding in general so go easy on me, i'm sure it's an easy answer but I just can't seem to figure it out and can't find a clear explanation.
Here's the part of the code I'm having troubles with:
while True:
try:
copies=float(input("Enter the number of copies to be printed --> "))
except ValueError:
print("Please enter a number.")
pass
else:
break
if copies < 100:
ppc=0.30
elif copies < 500 > 99:
ppc=0.28
elif copies < 750 > 499:
ppc=0.27
elif copies < 1001 > 749:
ppc=0.26
elif copies >1000:
ppc=0.25
total=(ppc*copies)
After I need to print the outputs of the price per copy (ppc) and the total price (ppc*copies). Easy enough until I try to make sure the values come out formatted as currecy, so 2 decimals (1.25, 1.30, etc.)
Can someone give me a hand and either write the last line of code I can evaluate or explain what I may need to do? I've looked at other examples for things like %0.2f % or whatever it is but I don't understand the lingo well enough to fit this to my assignment.
Thanks in advance.
I'm new to python and coding in general so go easy on me, i'm sure it's an easy answer but I just can't seem to figure it out and can't find a clear explanation.
Here's the part of the code I'm having troubles with:
while True:
try:
copies=float(input("Enter the number of copies to be printed --> "))
except ValueError:
print("Please enter a number.")
pass
else:
break
if copies < 100:
ppc=0.30
elif copies < 500 > 99:
ppc=0.28
elif copies < 750 > 499:
ppc=0.27
elif copies < 1001 > 749:
ppc=0.26
elif copies >1000:
ppc=0.25
total=(ppc*copies)
After I need to print the outputs of the price per copy (ppc) and the total price (ppc*copies). Easy enough until I try to make sure the values come out formatted as currecy, so 2 decimals (1.25, 1.30, etc.)
Can someone give me a hand and either write the last line of code I can evaluate or explain what I may need to do? I've looked at other examples for things like %0.2f % or whatever it is but I don't understand the lingo well enough to fit this to my assignment.
Thanks in advance.