0

I'm trying to understand how to get 2 decimal places in this code. Codio is reading it as one. It is not requiring a float command. If I were to enter a float, where would I actually add the $%.2f command in regard to this string. I am very new to coding, so I just want to make sure that I am creating the proper syntax. Been working on this for hours.

if rentalCode == "B":
    budgetCharge = 40.00
    baseCharge = rentalPeriod * budgetCharge

elif rentalCode == "D":
   budgetCharge = 60.00
   baseCharge = rentalPeriod * budgetCharge

elif rentalCode == "W":
   budgetCharge = 190.00
   baseCharge = rentalPeriod * budgetCharge

print(baseCharge) 
Ryan Miller
  • 19
  • 1
  • 5
  • I hope you're referring to the documentation for the correct version? In py2.x the print formatting was different which has changed In py3.x along with other syntax as well. – ParvBanks Dec 05 '18 at 03:22

1 Answers1

1

Defining budgetCharge with 2 decimal places will have no use. You can specify how many decimal places by using format strings:

# old style
print('%.2f' % baseCharge)

# new style
print('{:.2f}'.format(baseCharge))
iz_
  • 15,923
  • 3
  • 25
  • 40