I'm stuck writing some code for an intro programming class. I'm pretty sure the mistake is probably that I mixed integers with strings trying to get a result, but I'm just not sure which code I need to replace after messing with it all day and getting many different traceback errors trying different options. Suggestions would be fantastic. I have read the documentation on strings that comes with python, and tried to find a reference to this error and how to work around it in my textbook. Anyway, here's the code with the traceback included at the bottom.
#milesPerGallon.py
#a program to compute fuel efficiency in a multi-leg journey.
#prompt for starting odometer reading, and give reading after each leg of journey
#blank line from user to stop entering data and get final reseult
#odom and gallons used must be >1, odometer reading and gallons used should
#be entered by user seperated by a space
#print out mpg for each leg and total avg mpg
def main():
odom1 = int(input("Please enter a starting value for the odometer: "))
odom2 = 0
tripmiles = 0
miles = 0
gallons = 0
tripgallons = 0
while True:
odom2, gallons = int(input("\nPlease enter odometer reading and gallons used (odometer gallons) [Enter if done]: "))
while odom2 and gallons != "":
if odom2 >1 and gallons > 1:
miles = odom2 - odom1
odom1 = odom2
tripmiles = tripmiles + miles
tripgallons = tripgallons + gallons
print("MPG for this leg: ", miles / gallons)
else:
print("\nMiles and gallons must be a positive number greater than 1, seperated by a single space.\n")
print("Your total average miles per gallon: ", tripmiles / tripgallons)
main()
##>>> ================================ RESTART ================================
##>>>
##Please enter a starting value for the odometer: 100000
##
##Please enter odometer reading and gallons used (odometer gallons) [Enter if done]: 100500 10
##Traceback (most recent call last):
## File "C:/Users/Dad/Documents/Python Programming/milesPerGallon.py", line 35, in <module>
## main()
## File "C:/Users/Dad/Documents/Python Programming/milesPerGallon.py", line 20, in main
## odom2, gallons = int(input("\nPlease enter odometer reading and gallons used (odometer gallons) [Enter if done]: "))
##ValueError: invalid literal for int() with base 10: '100500 10'