1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
gregori [183]
2 years ago
6

Create a dictionary that will hold AT LEAST 3 categories for food with at least 3 foods for each category. E.g. Fruits --> Ap

ple, Strawberries, Orange; Vegetables --> Carrots, Peas, Onions; etc.. Once you have populated your dictionary with categories AND foods for each category, output the all the categories and the foods that you have for them (e.g. Fruits: Apple, Strawberries, Orange). Ask the user if they would like to add a new category OR a new food. If they say a new category, make sure that it is actually a new category and not an existing one. If it is a food, add it to the list of foods that you already had. Ask the user if they would like to enter something else, and if they say yes, keep going, otherwise don't prompt them to input any more information. Once the user has added all of their information, output all of the categories for food and ask the user to pick one to see all of the foods. You only need to do this once, but feel free to make a loop to let them do this as many times as they want.
Computers and Technology
1 answer:
RSB [31]2 years ago
8 0

Answer:

  1. food_category = {
  2.    "Fruits": ["Apple", "Strawberries", "Orange"],
  3.    "Vegetables": ["Carrots", "Peas", "Onions"],
  4.    "Meats": ["Chicken", "Beef", "Mutton"]
  5. }
  6. for cat in food_category:
  7.    output = cat + ": "
  8.    for food in food_category[cat]:
  9.        output += food + ", "
  10.    print(output)
  11. answer = input("Do you want to add category or food (Y - Yes  N - No): ")
  12. while(answer == "Y"):
  13.    choice = input("New Category (N) or New Food (nf): ")
  14.    
  15.    if(choice == "N"):
  16.        new_cat = input("Enter new category name: ")
  17.        if(new_cat not in food_category):
  18.            food_category[new_cat] = ""
  19.    elif(choice == "nf"):
  20.        cat = input("Enter category: ")
  21.        new_food = input("Enter new food name: ")  
  22.        food_category[cat].append(new_food)
  23.    
  24.    answer = input("Do you want to add new category or food (Y - Yes N - No): ")
  25. print("All food categories: ")
  26. for cat in food_category:
  27.    print(cat)
  28. selected_cat = input("Select a category to view the food list: ")
  29. output = ""
  30. for food in food_category[selected_cat]:
  31.    output += food + ", "
  32. print(output)

Explanation:

The solution code is written in Python 3.

Firstly, create a food category dictionary data structure (Line 1 -5). Next, display all the food category and the food in each category (Line 7 - 11)

Next prompt user to feedback if they wish to add new category or new food (Line 13).

While the answer is yes prompt user to enter their choice, either category or food and use if else if statements to handle the choice made by the user. If the choice is new category, prompt user to enter new category name and check if the new category is already exist in the dictionary. If not, add that category to dictionary (Line 18 - 21).

If the choice is food, nf, prompt user to input food category and enter the new food name and add it to the food_category list (Line 22 - 25).

After that prompt user to enter if they wish to continue to add new data (Line 27).

After collecting all info from user, write a for loop to display all the categories (Line 29 - 31).

At last, prompt user to select a category and display all the food of the selected category (Line 33 - 37).

You might be interested in
Hich is an aspect of spatial-level design?
Tresset [83]

The answer is perspective, because you need a point of view (perspective) in order to make a design, a great design/

4 0
3 years ago
Read 2 more answers
Is this the usb cable that transfers pdf files from a phone to a another computer that doesn't belong to mines?
Dmitrij [34]

yes that is a usb cable

hope that helped

5 0
3 years ago
What analogy could you use to explain the hardware parts of a computer?
zvonat [6]

Answer:

Take a piece of paper for example. You can write on it. The words the paper is the software because they are a  thought description of what you want to express.

In contrast, the ink, pen, and paper that is used to write those words are the hardware parts because they are physical objects that is used to create that thought description.

3 0
2 years ago
A String variable, fullName, contains a name in one of two formats:last name, first name (comma followed by a blank), orfirst na
Volgvan

Answer:

#include <iostream>

using namespace std;

int main()

{

   char fullname[30];

   string fname="",lname="";

   int i,j;

   cout<<"Enter fullname\n";

   cin.getline(fullname,30); //so that blank can be read

   for(i=0;fullname[i]!=' ';i++)

       fname+=fullname[i];   //fistname will be saved

      cout<<"\n";

   for(j=i;fullname[j]!='\0';j++)

       lname+=fullname[j];    //lastname will be saved

   cout<<"\nFirstname : "<<fname<<"\nLastname : "<<lname;

   return 0;

}

OUTPUT :

Enter fullname

John thomson

Firstname : John

Lastname : thomson

Explanation:

cin.getline() should be used instead of cin in case of strings so that space can be read otherwise after blank string will be ignored.

8 0
3 years ago
Run net start "network access protection agent" on the windows 7 computers
aivan3 [116]
What is the question
3 0
3 years ago
Other questions:
  • How can i do a back up on one computer and save it to the hard drive in another computer without it being seen by others on the
    9·1 answer
  • Write a function called median, that takes as parameter a full, sorted array of doubles and returns the median of the list. For
    15·1 answer
  • What does txt atm mean? what does txt atm mean
    8·1 answer
  • What is hyper transport
    10·1 answer
  • Driver’s License Exam The local driver’s license office has asked you to create an application that grades the written portion o
    9·1 answer
  • Write 5 chart types​
    12·1 answer
  • A ___________ variable is used to add up a set of values. fill in the blank
    8·1 answer
  • )
    11·1 answer
  • Who is in the age range of 13-15 and wants to join a mine craft smp?
    8·1 answer
  • Three primary types of data that a forensic investigator must collect, in this order: 1.Volatile data 2.Temporary data 3.Persist
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!