Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View cybnz's full-sized avatar

Ben Jones cybnz

  • Tauranga, Bay of Plenty, New Zealand
View GitHub Profile
@cybnz
cybnz / 06_convert_mls.py
Created August 2, 2020 06:08
Basic unit to mL converter (does not cope with abbreviations)
# ask user for amount
# ask user for Unit
# check that unit is in dictionary
# if unit in dictionary, convert to mL
# if no unit is given / unit is unknown, leave as is
unit_central = {
"tsp": 5,
@cybnz
cybnz / 05_scale_ingredients.py
Created August 2, 2020 05:03
Scales ingredients correctly but formatting needs to be fixed
# Ingredients list
# Number Checking Function
def num_check(question):
error = "Please enter a number that is more than zero"
valid = False
while not valid:
response = input(question)
@cybnz
cybnz / 05_scale_ingredients.py
Created August 2, 2020 04:48
Get ingredient amount and scale it
# Ingredients list
# Number Checking Function
def num_check(question):
error = "Please enter a number that is more than zero"
valid = False
while not valid:
try:
@cybnz
cybnz / 03_find_scale_factor.py
Created August 2, 2020 03:23
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:
@cybnz
cybnz / 03_find_scale_factor.py
Created August 2, 2020 02:33
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:
@cybnz
cybnz / 03_find_scale_factor.py
Created August 2, 2020 02:05
Finds sf but does not check input
# Functions go here
# Main Routine goes here
serving_size = float(input("What is the recipe serving size? "))
desired_size = float(input("How many servings are needed? "))
scale_factor = desired_size / serving_size
print("Scale factor: {}".format(scale_factor))
@cybnz
cybnz / 01_recipe_name.py
Created July 31, 2020 02:34
Checks for blanks and numbers
# Get's recipe and checks it is not blank
# Not Blank Function goes here
def not_blank(question):
error = "Your recipe name has numbers in it."
valid = False
while not valid:
response = input(question)
has_errors = ""
@cybnz
cybnz / 01_recipe_name.py
Created July 30, 2020 22:19
Checks for blanks but allows numbers
# Get's recipe and checks it is not blank
# Not Blank Function goes here
def not_blank(question):
valid = False
while not valid:
response = input(question)
if response == "":
continue