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
Write function d2x() that takes as input a nonnegative integer n (in the standard decimal representation) and an integer x betwe
Rufina [12.5K]

Answer:

The function in Python is as follows:

def d2x(d, x):

   if d > 1 and x>1 and x<=9:

       output = ""

       while (d > 0):

           output+= str(d % x)

           d = int(d / x)

       output = output[::-1]

       return output

   else:

       return "Number/Base is out of range"

Explanation:

This defines the function

def d2x(d, x):

This checks if base and range are within range i.e. d must be positive and x between 2 and 9 (inclusive)

   if d >= 1 and x>1 and x<=9:

This initializes the output string

       output = ""

This loop is repeated until d is 0

       while (d > 0):

This gets the remainder of d/x and saves the result in output

           output+= str(d % x)

This gets the quotient of d/x

           d = int(d / x) ----- The loop ends here

This reverses the output string

       output = output[::-1]

This returns the output string

       return output

The else statement if d or x is out of range

<em>    else:</em>

<em>        return "Number/Base is out of range"</em>

<em />

4 0
3 years ago
GIVING BRAINLIEST What does output allow a computer to do? Display information Receive information Do complex math problems Do m
kumpel [21]
The answer is display information
4 0
3 years ago
Read 2 more answers
Which of the following is not an Error Style for data validation?
Brut [27]

Based on the Microsoft Excel data validation, the option that is not an Error Style for data validation is the <em><u>choice that does not show an error alert.</u></em>

Given that there is no option available, the best way to answer this question is to show the types of Error Styles for data validation available.

<h3>Different types of Error Style for data validation</h3>
  • Stop style: this will bring the option of "Retry, " "Cancel, " and "Help."

  • Warning style: this will show "Continue," with options of "Yes," "No," "Cancel," and "Help."

  • Information Style: this will ask you to input the whole number with the option of "Ok," "Cancel," and "Help."

Hence, in this case, it is concluded that the Error Style for data validation is Stop, Warning, and Information Style.

Learn more about Error Style for data validation here: brainly.com/question/18497347

4 0
2 years ago
Snap Me on <br>samxavier.18​
Ahat [919]

Answer:no thank you ima goody

Explanation:

7 0
2 years ago
Read 2 more answers
Hillary’s family is thinking of relocating to a different city to save money. They set up a budget comparing the cost of living
vova2212 [387]

Answer: Oakland, and also a city they feel is the safest + best for there family

Explanation:

3 0
2 years ago
Other questions:
  • 1. Which sign-in method requires users to press Ctrl+Alt+Delete before signing in?
    5·1 answer
  • What is the answer and why?
    12·1 answer
  • The software used to help run the computer hardware is the _____.
    9·2 answers
  • Generally considered to be the most important information security policies, what item below defines the actions a user may perf
    11·1 answer
  • Green field country is planning to conduct a cricket match between two teams A and B. a large crowd is expected in the stadium a
    6·1 answer
  • Memory cache is referred to as ______. A. SRAM c. SROM b. DRAM d. DROM
    11·1 answer
  • How was the addition of an improvement over early web design?
    11·1 answer
  • Who is the fan of Techno gamerz and Total gaming
    10·1 answer
  • I really need help in this!!!
    11·1 answer
  • what extension of nat allows several hundred workstations to access the internet with a single public internet address
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!