Starting out with Python 4th edition
Chapter 2 Programming Exercise 10 Ingredient Adjuster
Not sure how to do this
CODE
def main():
cookies = float(input("How many cookies would you like to make?\n>"))
# Calulate sugar ((1.5 * cookies) / 48)
# Store answer (sugar)
sugar = (1.5 * cookies) / 48.0
# Calculate butter (cookies / 48)
# Store answer (butter)
butter = cookies / 48
# Calculate flour ((2.75 * cookies) / 48)
# Store answer (flour)
flour = (2.75 * cookies) / 48
print("To make ", cookies, " cookies, you will need:\n", \
format(sugar, '.2f'), " cups of sugar\n", \
format(butter, '.2f'), " cups of butter\n", \
format(flour, '.2f'), " cups of flour", sep='')
iterate()
def iterate():
yn = input("Want to continue(y/n) ? ")
if yn == 'y' or yn == 'Y':
main()
exit(0)
if __name__ == "__main__":
main()
Get Answers For Free
Most questions answered within 1 hours.