Advertisement
AceScottie

input python

Aug 4th, 2018
430
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.51 KB | None | 0 0
  1. while True: ##loop forever
  2.     try: #tries the lines
  3.         x = input('enter paitent weight in Kg>') #get the users input
  4.         x = float(x) # converts the input to a float (floating point number, example: 0.1)
  5.         break #break out of the while loop
  6.     except: #if the tried lines had an error then this runs instead
  7.         print("sorry {} was not a number, please try again".format(x)) #simple print statement with variables
  8.  
  9. if isinstance(x, float): #checks to make sure a variable is of a certian type
  10.     print(x)#prints the varialbe
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement