Skip to content

Instantly share code, notes, and snippets.

Avatar

Ben Jones cybnz

  • Tauranga, Bay of Plenty, New Zealand
View GitHub Profile
@cybnz
cybnz / 06_convert_mls.py
Created Aug 2, 2020
Basic unit to mL converter (does not cope with abbreviations)
View 06_convert_mls.py
# 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 Aug 2, 2020
Scales ingredients correctly but formatting needs to be fixed
View 05_scale_ingredients.py
# 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 Aug 2, 2020
Get ingredient amount and scale it
View 05_scale_ingredients.py
# 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 Aug 2, 2020
Finds sf, only between 1/4 and 4
View 03_find_scale_factor.py
# 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 Aug 2, 2020
Finds sf and checks if number and more than 0
View 03_find_scale_factor.py
# 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 Aug 2, 2020
Finds sf but does not check input
View 03_find_scale_factor.py
# 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 Jul 31, 2020
Checks for blanks and numbers
View 01_recipe_name.py
# 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 Jul 30, 2020
Checks for blanks but allows numbers
View 01_recipe_name.py
# 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