Calculate the bill by distance covered.

In this program, we will calculate the bill by distance covered.

Steps to solve the program
  1. Take Km covered as input through the user.
  2. Create three variables and assign their values equal to 0.
  3. In the first variable calculate the Km covered in the first 5 Km.
  4. In the second variable calculate the Km covered for the next 20 Km.
  5. In the third variable calculate the Km covered for further distance.
  6. Use for loop to calculate it.
  7. Finally, calculate the bill according to the Km covered.
  8. 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
				
			

get input from the user if it is a string insert it into an empty list

Calculate the electricity bill

Leave a Comment