![]() |
Loops - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Homework (https://python-forum.io/forum-9.html) +--- Thread: Loops (/thread-10582.html) |
Loops - alwillia - May-26-2018 for i in range(3): category = input("Enter a Category: ") for j in range(3): enter_for_category = input("Enter Something in that category: ")This is what i'm supposed to do: Write a program that asks the user for three categories. For each category, ask the user for three things in that category. You should print something for each category that states the category and the three things in that category. Here is what running your final program should look like: Enter a category: animals Enter something in that category: cheetah Enter something in that category: pelican Enter something in that category: red panda animals: cheetah pelican red panda Enter a category: noises Enter something in that category: vroom! Enter something in that category: whirrr! Enter something in that category: whooosh! noises: vroom! whirrr! whooosh! Enter a category: programming languages Enter something in that category: Python Enter something in that category: Java Enter something in that category: C++ programming languages: Python Java C++ This is my results: Enter a Category: animals Enter Something in that category: bird Enter Something in that category: cat Enter Something in that category: dog Enter a Category: noise Fixed RE: Loops - killerrex - May-26-2018 You need to store the answers from the user in a structure of data (so store somehow your enter_for_category in a data structure) To put it clear, you can solve your exercise with the following: for i in range(3): category = input("Enter a Category: ") # The next lines are a cry to suspend... a = input("Enter Something in that category: ") b = input("Enter Something in that category: ") c = input("Enter Something in that category: ") # Report the results: print(f"{category}: {a} {b} {c}")So you see what you shall change... you need to replace the "a, b, c" with a data structure that allows you to fill it with a loop. Take a look to the dict and list in the python documentation. |