Skip to content

Instantly share code, notes, and snippets.

@cybnz
Created August 2, 2020 02:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cybnz/7611f89254f91caddcfb493d67566fe4 to your computer and use it in GitHub Desktop.
Save cybnz/7611f89254f91caddcfb493d67566fe4 to your computer and use it in GitHub Desktop.
Finds sf and checks if number and more than 0
# Functions go here
def num_check(question):
error = "Please enter a number that is more than zero"
valid = False
while not valid:
try:
response = float(input(question))
if response <= 0:
print(error)
else:
return response
except ValueError:
print(error)
# Main Routine goes here
serving_size = num_check("What is the recipe serving size? ")
desired_size = num_check("How many servings are needed? ")
scale_factor = desired_size / serving_size
print("Scale factor: {}".format(scale_factor))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment