Write a function that calculates a taxi fare for the travelers. Your program should get the information of the distance traveled by the customer and calculate the taxi fare and should display it to the passenger for the payment to be received. The taxi fare consists of a base fare of RM 4.00 plus charges of RM 0.25 for every 140 meters traveled. Define and call the function accordingly.
#The start point of the program
def main():
#Get the information of the distance traveled by the customer
distanceTraveled=int(input("The distance traveled by the customer (in KM): "))
#calculate the taxi fare
taxiFare=calculateTaxiFare(distanceTraveled)
#display it to the passenger for the payment to be received.
print(f"The taxi fare is: ${taxiFare}")
#This function allows to calculate the taxi fare
def calculateTaxiFare(distanceTraveled):
#The taxi fare consists of a base fare of RM 4.00
#plus charges of RM 0.25 for every 140 meters traveled.
return 4.00+(((distanceTraveled*1000)//140)*0.25)
main()
Comments
Leave a comment