1) We have returned to our ingredients dictionary. We want to display the ingredients in alphabetical order. Dictionaries cannot be sorted, so we need to use the items method to convert the dictionary into a list of tuples. Then we can sort that new list of tuples, then display the ingredients.
When you do these steps, you should match the output under Desired Output.
# Assign ingredients to a dictionary of
# food ingredients
ingredients = {"eggs":1, "flour":"1 cup", "sugar":"1 cup",
"cocoa":"0.5 cups"}
# Use items() and list() to convert
# the dictionary /ingredients/
# into a list of tuples
ingred_list =
# Sort the list /ingred_list/
# Use a for Statement to display
# ingredients in /ingred_list/
desired output:
cocoa 0.5 cups eggs 1 flour 1 cup sugar 1 cup
2)
We have a very simple recipe for a glass of water. Use a for loop and a print statement to display the ingredients using key/value pairs.
Note: do not just write print("water 1 cup")!
When you are finished, you should match the output under Desired Output.
# Assign ingredients
ingredients = {"water":"1 cup"}
# Use a /for/ loop and /print/ statement
# to display the ingredients:
desired output:
water 1 cup
3)
We want to see how much flour we need and whether this recipe contains butter.
When you are completed, your output should match the Desired Output.
# Assign ingredients to a dictionary of
# food ingredients
ingredients = {"eggs":1, "flour":"1 cup", "sugar":"1 cup",
"cocoa":"0.5 cups"}
# Display the /flour/ quantity
print("Flour:")
# Check if this recipe takes butter:
if :
print("This recipe takes butter!")
else:
print("No butter in this recipe!")
desired output:
Flour: 1 cup No butter in this recipe!
# Assign ingredients to a dictionary of # food ingredients ingredients = {"eggs":1, "flour":"1 cup", "sugar":"1 cup", "cocoa":"0.5 cups"} # Use items() and list() to convert # the dictionary /ingredients/ # into a list of tuples ingred_list = list(ingredients.items()) # Sort the list /ingred_list/ ingred_list.sort() # Use a for Statement to display # ingredients in /ingred_list/ for (i, q) in ingred_list: print(i, ':', q) ##################################################### ##################################################### # Assign ingredients ingredients = {"water":"1 cup"} # Use a /for/ loop and /print/ statement # to display the ingredients: for (i, q) in ingredients.items(): print(i, q) ##################################################### ##################################################### # Assign ingredients to a dictionary of # food ingredients ingredients = {"eggs":1, "flour":"1 cup", "sugar":"1 cup", "cocoa":"0.5 cups"} # Display the /flour/ quantity print("Flour:", ingredients['flour']) # Check if this recipe takes butter: if 'butter' in ingredients: print("This recipe takes butter!") else: print("No butter in this recipe!")
Please upvote, as i have given the exact answer as asked in
question. Still in case of any issues in code, let me know in
comments. Thanks!
1) We have returned to our ingredients dictionary. We want to display the ingredients in alphabetical...
A cookie recipe calls for the following ingredients: • 1.5 cups of sugar • 1 cup of butter • 2.75 cups of flour The recipe produces 48 cookies with this amount of ingredients. Write a program that asks the user how many cookies they want to make and then displays the number of cups of each ingredient needed for the specified number of cookies in the following format: You need 5 cups of sugar, 3 cups of butter, and 7...
Homework P Do Homework - BreAnna ON C mathxl.com Homework: HW 6.4 Score: 0 of 1 pt 6.4.42 1 The list of ingredients for chocolate brownies given at right will make 16 brownies. Use the list to decide how much of each ingredient is needed to make 12 brownies cup butter 2 ounces unsweetened chocolate 1 cups sugar teaspoons vanilla 2 1 2 eggs 3 cup flour cup(s) of butter is needed. (Simplify your answer. Type an integer, simplified fraction,...
In PYTHON ONLY PLEASE You will use a dictionary in Python You only have string in Python so you have to use a string data type Use a Switch statement.A switch statement is just another way of writing an IF statement. The user will enter f, s, j, or r from the keyboard for freshman, sophomore, junior, or senior. Use character data type for c++. Then you can say something like: char level ='f'; level=toupper(level); You would need a loop...
Python please For this program, we will be making lists for the local Zoo. You have been provided with 4 lists of data already created for you. Using this data, we update the data at this Zoo. YOU MUST USE LIST FUNCTIONS FOR REMOVING TO RECEIVE YOUR FULL POINTS! Input: A type of animal -- This information should be provided in response the question: "What animal are we removing?" A number corresponding to the selection of a menu number (see...
Homework - 4 Name: 1- Intake Analysis Carbohydrates Eating Plan B (1 Day's Intake) 6 ounces grapefruit juice 2 scrambled eges 1 ounce cheddar cheese 20 ounces coffee 2 ounces soy milk 1 cup fresh raspberries 1 cup cantaloupe 1 honey oat granola bar 1 cup vanilla yogurt 6 ounces grilled salmon 10 cooked asparagus spears 1 cup broccoli 4 ounces white wine 4 ounces blueberry juice + seltzer water 20 barbecue flavor soy crisps 1 cup wasabi peas 13"...
Could anyone help add to my python code? I now need to calculate the mean and median. In this programming assignment you are to extend the program you wrote for Number Stats to determine the median and mode of the numbers read from the file. You are to create a program called numstat2.py that reads a series of integer numbers from a file and determines and displays the following: The name of the file. The sum of the numbers. The...
(Write or type in answers, except for problem #15, which should be entered as a small program, tested, and submitted in Repl.it) 1. Write a Python statement to define a list named temps using the following elements, in order: 95, 100, 77, 54, 103, 82 2. a) What is the length of the list temps? b) What Python function can be used to obtain the length of the list? Use it in a statement to obtain the length of temps...
Suppose that we want to help physicians to diagnose illnesses. A physician observes a patient's symptoms and considers the illnesses that could be associated with those symptoms. Design and implement a class PhysiciansHelper thatprovide a list of those illnesses. PhysiciansHelper should contain a dictionary of illnesses and symptoms. A method should read a text file of illnesses and their symptoms into the dictionary. See format in sample data file. PhysiciansHelper should read a list of symptoms for a patient. A...
Python program This assignment requires you to write a single large program. I have broken it into two parts below as a suggestion for how to approach writing the code. Please turn in one program file. Sentiment Analysis is a Big Data problem which seeks to determine the general attitude of a writer given some text they have written. For instance, we would like to have a program that could look at the text "The film was a breath of...
1. What are the objectives of the Chipotle ad (page 579)? Does
the ad have more than one objective?
MEAT, NO PRESCRIPTION NEEDED. Chipotle rice.com NO ADDED HORMONES OR ANTIBIOTICS IN ARIZONA CHANDLER FASHION CENTER NEXT TO HARKINS THEATRE San Tan Signs Then it comes down to it, what is the point of advertising? Generally we think that its goal is to get someone-normally the person receiving the ad-to do some thing and that something is nearly always a purchase...