Programming Exercise 8: Your Own Recipe Multiplier Program Purpose. In this last exercise you get to apply all that you’ve learned about programming so far, to make something useful. This program...

you can usePython3


Programming Exercise 8: Your Own Recipe Multiplier Program Purpose. In this last exercise you get to apply all that you’ve learned about programming so far, to make something useful. This program adjusts the amounts of ingredients in a recipe to make a number of servings that’s different from the number of servings that the recipe makes. You’ll also learn another useful application of the hash symbol for comments outside of the comment block itself, to provide a detailed description of a variable in the variables code block. Background. You know how to create variables for storing numbers, but to this point we’ve only ever assigned values to the inputted variables. These examples show how to “hard-wire” an ingredient for a recipe, with a variable name to identify the ingredient and its unit of measure: Note that there are no single or double quote marks around the numbers. This is what tells Python that these are numbers and not text. This allows them to be used in the math calculations it’s going to take to convert the amounts for a different number of servings. But first we need to know how many servings that the original recipe makes: Note the one new thing here is the hash symbol and the comment that follows it. This is a comment that’s added to the end of a non-comment statement, to allow detailed description that’s hard to put into a variable’s name. Next we need to know how many servings we want to make, using this recipe. We can get that from an input prompt like this: Finally, here’s how to convert each ingredient, and round off the result before printing it – the following rounds to two decimal digits, because of the “2” inside “%.2f”: Something You Should Know. Rounding actually converts a value from a number to text. So if you want to use a converted value in a calculation again, you’d need to use float(…) as explained in exercise 6, like this: tspSugar = float(tspSugar). Your Turn. Write a program to convert your favorite recipe. Use as many ingredients as you like, as long as it’s at least three. In your output, say the name of the recipe, the inputted number of servings, and the full name and amount of each ingredient, like this: Submitting Your Work. Submitting Your Work. Submit your work as you did in all previous exercises. Take a screen shot of your code including the output after you run your program, save it in Paint as firstname_lastname_lesson8.png. We are DONE! [Type text][Type text][Type text] Comsc 101Page 1 of 1Programming Exercise 8
Nov 07, 2021
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here