SHARE
TWEET

Untitled

a guest Jun 24th, 2019 77 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # To Do
  2.  
  3. #Ask user for servings made by recipe (and check this is a number that is more that
  4. #Ask user for servings desired (check this is a number)
  5. #Calcualte the scale factor
  6. #Warn the user if the sf is less than 0.25 or more than 4
  7.  
  8. #functions go here
  9.  
  10. # Number Checking Function
  11. def num_check(question):
  12.  
  13.     error = "Please enter a number that is more than zero"
  14.  
  15.     valid = False
  16.     while not valid:
  17.         try:
  18.              response = float(input(question))
  19.  
  20.              if response <= 0:
  21.                  print(error)
  22.              else:
  23.  
  24.                   return response
  25.  
  26.         except ValueError:
  27.              print(error)
  28.  
  29. # Main Routine goes here
  30.  
  31. serving_size = num_check("What is the recipe serving size? ")
  32. desired_size = num_check("How many servings are needed? ")
  33.  
  34. scale_factor = desired_size / serving_size
  35.  
  36. print("Scale Factor: {}".format(scale_factor))
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top