In: Computer Science
Drivers are concerned with the mileage obtained by their
automobiles. One driver has kept track of several tankfuls of fuel
by recording the kilometres driven and the litres used for each
tankful. Develop a python program that prompts the user to input
the kilometres driven and litres used for each tankful. The program
should calculate and display the kilometres per litre obtained for
each tankful. Read inputs for at least 10 such readings. After
processing all input information, the program should calculate and
print the combined kilometres per litre obtained for all tankfuls
(= total kilometres driven divided by total litres used).
-Language used is Python. Please form the code for this
scenario.
total_kilometres = 0
total_litres = 0
# Read inputs for at least 10 such readings.
for i in range(10):
print(f"For tankful #{i+1}")
# prompts the user to input the kilometres driven
kilometres = int(input("\nEnter kilometres driven: "))
# prompts the user to input the litres used for each tankful.
litres = int(input("Enter litres used: "))
total_kilometres += kilometres
total_litres += litres
# calculate and display the kilometres per litre obtained for each tankful.
print("\nkilometres per litre is obtained for this tankful:", kilometres/litres)
# print combined output
print("\ncombined kilometres per litre:",
round(total_kilometres/total_litres))
.
Screenshot:
Output:
.