I am quite new to python. I have this problem where I should write a program that calculates a customer monthly bill. It should ask which package the customer has purchased (package A, B or C), what month (in terms of numeric), and how many hours were used. It should then display the total amount due.
Also the number of hours should not exceeds the total number of hours per month (assuming every month has 30 days = 720 hours).
The specifications are:
Package A: For Php200.00 per month, 10 hours of access are provided. Additional hours are Php15.00 per hour.
Package B: For Php500.00 per month, 20 hours of access are provided. Additional hours are Php10.00 per hour.
Package C: For Php900.00 per month, unlimited access is provided.
My code is working as intended so far. But I also want to keep looping the 2nd and 3rd Input ("month" and "hours") as long as the input is wrong and then proceed to the next.
here is my code:
price_A = 200.00
price_B = 500.00
price_C = 900.00
Package = ""
package = False
while Package not in ("A", "a", "B", "b", "C", "c"):
Package = input("Enter package: ")
package = True
if Package in ("A", "a"):
month = int(input("Enter month: "))
if int(float(month)) >= 1 and int(float(month)) <= 12:
hours = int(input("Enter hours: "))
if int(float(hours)) >= 0 and int(float(hours)) <= 720:
if int(float(hours)) >= 0 and int(float(hours)) <= 10:
total = price_A
f_total = "{:.2f}".format(total)
print("Total amount due is Php " + f_total)
elif int(float(hours)) >= 10:
total = ((hours - 10) * 15.00) + price_A
f_total = "{:.2f}".format(total)
print("Total amount due is Php " + f_total)
else:
print("Invalid Hours!")
else:
print("Invalid Month!")
elif Package in ("B", "b"):
month = int(input("Enter month: "))
if int(float(month)) >= 1 and int(float(month)) <= 12:
hours = int(input("Enter hours: "))
if int(float(hours)) >= 0 and int(float(hours)) <= 720:
if int(float(hours)) >= 0 and int(float(hours)) <= 20:
total = price_B
f_total = "{:.2f}".format(total)
print("Total amount due is Php " + f_total)
elif int(float(hours)) >= 20:
total = ((hours - 10) * 10.00) + price_B
f_total = "{:.2f}".format(total)
print("Total amount due is Php " + f_total)
else:
print("Invalid Hours!")
else:
print("Invalid Month!")
elif Package in ("C", "c"):
f_total = "{:.2f}".format(price_C)
print("Total amount due is Php " + str(f_total))
else:
print("Invalid Package!")
I still do not know where should I put the while loop for the 2nd and 3rd Inputs.