here i have made code, how could i imporve this version of my code, and make it more effeicnt. below is the code.
i have Write a program that asks the user to input
• The capacity in gallons of a fuel tank
• The fuel efficiency in miles per gallon
• The price of a gallon of petrol
Then outputs:
• how far the car can go with the gas in the tank (capacity x mpg)
• and the cost per 100 miles. (100/mpg*price)
i have to also Ensure the output is in integer format, to a precision of 5.
i have Write a program that asks the user to input
• The capacity in gallons of a fuel tank
• The fuel efficiency in miles per gallon
• The price of a gallon of petrol
Then outputs:
• how far the car can go with the gas in the tank (capacity x mpg)
• and the cost per 100 miles. (100/mpg*price)
i have to also Ensure the output is in integer format, to a precision of 5.
Code:
print "--------Welcome To Fuel Calculator Program--------"
capacity = input ("\nPlease enter the capacity of the fuel tank in gallons: ")
mpg = input ("Please enter the fuel efficiency in MPG: ")
pricepergallon = input ("Please enter the price per gallon of petrol? £: ")
carcango = capacity * mpg
print "\n\nOn a full tank, the car can travel:","\t%.5d" % carcango, "miles"
print "The cost of travelling 100 miles is: \t£""%.5d" % (100.0/mpg *pricepergallon)
print "\n--------End Program--------"
Comment