Can u help? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Can u help?

You are making a robot that should categorize items by their color. Each color corresponds to a box with a specific number. For simplicity, our program will handle 3 colors: red goes to box #1 green goes to box #2 black goes to box #3 Your program needs to take a color as input and output the corresponding box number. Sample Input green Sample Output 2

21st Jul 2023, 7:06 AM
Chadwick John A Balota
Chadwick John A Balota - avatar
5 Answers
+ 6
Chadwick John A Balota Share your attempt so we can help
21st Jul 2023, 7:46 AM
Junior
Junior - avatar
+ 3
Otid please don't give the readymade code the opponent will not learn by yourself, firstly see the user will attempt or not then give the hint if the user have doubt but don't send completely code until the user don't understand the hint. Hope you will understand what I mean to say.
21st Jul 2023, 3:27 PM
Sakshi
Sakshi - avatar
+ 3
Sakshi Thank you for the feedback! I understand, and will keep that in mind going forward. Here's a hint that might help: You can use a dictionary to store the colors and their corresponding box numbers. Then you can simply access the box number using the color as the key. Would you like a code example that implements this hint?
21st Jul 2023, 3:32 PM
Otid Kartgepsut
Otid Kartgepsut - avatar
+ 1
Here's an example Python program that categorizes items by their color: ```python color = input("Enter item color: ") if color == "red": print("Box #1") elif color == "green": print("Box #2") elif color == "black": print("Box #3") else: print("Invalid color") ``` The program prompts the user to enter a color and then uses an if-elif-else statement to determine the corresponding box number. If the input is not a valid color, the program outputs "Invalid color". To categorize more colors, you can simply add more elif statements with their corresponding box numbers.
21st Jul 2023, 7:56 AM
Otid Kartgepsut
Otid Kartgepsut - avatar
0
Thankss
21st Jul 2023, 9:09 AM
Chadwick John A Balota
Chadwick John A Balota - avatar