In: Computer Science
Write a python program that uses a conditional loop to ask the user for distance and gallons and calculates the MPG. The program should store data in a text file as shown below: Distance Gallons MPG 225 17 13.24 1374 64 21.47 2514 79 31.82
f=open("output.txt","w")
f.write("Distance\tGallons\tMPG\n")
while(True):
distance=float(input("Enter distance and gallons (-1 to exit): "))
if(distance==-1):
break
gallons=float(input(""))
mpg=distance/gallons
f.write(str(distance)+"\t"+str(gallons)+"\t"+str(mpg)+"\n")
f.close()

Note : Please comment below if you have concerns. I am here to help you
If you like my answer please rate and help me it is very Imp for me