Advertisement
Guest User

Untitled

a guest
Nov 20th, 2017
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.81 KB | None | 0 0
  1. def is_number(s):
  2.     try:
  3.         float(s)
  4.         return True
  5.     except ValueError:
  6.         return False
  7. print("Hello, welcome to the gas milage calculator. For testing purposes, please try to input both numbers and non numbers to see how the program reacts. Thank you!")
  8. x = input("Please input the number of galons of gas used: ")
  9. while is_number(x) == False:
  10.     print("Oops! This is not a number.")
  11.     x = input("Please input the number of galons of gas used: ")
  12. while is_number(x) == True:
  13.         y = input("Please input the number of miles traveled: ")
  14.         if is_number(y) == True:
  15.             print("Your gas milege is: ", float(y) / float(x), 'miles per gallon.')
  16.             input("Press any key to exit: ")
  17.             break
  18.         else:
  19.             print("Oops! This is not a number.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement