I'm new to python and am trying to check if startmiles
and endmiles
are input as integer only and gallons
are input as float. When I enter alpha the program crashes. Thank You
#!/usr/bin/env python
import os
import sys
import subprocess
import datetime
clear = lambda: os.system('clear')
clear()
t = datetime.datetime.now()
from time import gmtime, strftime
strftime("%a, %d %b %Y %X +0000", gmtime())
today = strftime("%a, %d %b %Y ")
print(today,'\n')
def main():
startmiles = input("Enter Your Start Miles = ")
endmiles = input("Enter Your Ending Miles = ")
gallons = input("Enter Your Gallons = ")
mpg = (int(endmiles) - int(startmiles)) / float(gallons)
print("Miles Per Gallon =", round(mpg, 2))
answer = input("\n Go Again Y or n ").lower()
if answer == 'y': print('\n'), main()
if answer != 'y': print('\n Thank You Goodbye')
if __name__=="__main__":
main() # must be called from last line in program to load all the code