In this program, we will calculate the bill by distance covered.
Steps to solve the program
- Take Km covered as input through the user.
- Create three variables and assign their values equal to 0.
- In the first variable calculate the Km covered in the first 5 Km.
- In the second variable calculate the Km covered for the next 20 Km.
- In the third variable calculate the Km covered for further distance.
- Use for loop to calculate it.
- Finally, calculate the bill according to the Km covered.
- Print the output.
km = int(input("Enter the KM covered: "))
bill = 0
a=b=c=0
for i in range(1,km+1):
if i<6:
a += 1
elif i>5 and i<26:
b += 1
elif i>25:
c += 1
bill = a*5 + b*12 + c*10
print("Total bill: ", bill)
Output :
Enter the KM covered: 15
Total bill: 145