Skip to content

Instantly share code, notes, and snippets.

@cybnz
Created August 2, 2020 03:23
Show Gist options
  • Save cybnz/34485600b422c0524a7079a48ab10ff8 to your computer and use it in GitHub Desktop.
Save cybnz/34485600b422c0524a7079a48ab10ff8 to your computer and use it in GitHub Desktop.
Finds sf, only between 1/4 and 4
# 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
sf_ok = "no"
while sf_ok == "no":
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
if scale_factor < 0.25:
sf_ok = input("Warning: this scale factor is very small and you might struggle to accurately weigh the ingredients. Please consider using a larger scale factor and freezing the left-overs. \nDo you want to keep going (type 'no' to change your desired serving size) ").lower()
elif scale_factor > 4:
sf_ok = input("Warning: this scale factor is quite large - you might have issues with mixing bowl volumes and oven space. Please consider using a smaller scale factor and making more than one batch. \nDo you want to keep going (type 'no' to change your desired serving size) ").lower()
else:
sf_ok = "Yes"
print("Scale factor: {}".format(scale_factor))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment