In: Computer Science
PYTHON PROGRAMMING
The colors red, blue, and yellow are known as the primary colors because they cannot be made by mixing other colors. When you mix two primary colors, you get a secondary color, as shown here:
For this program, you will employ list data structures to store a group of objects by designing a program that prompts the user to enter the names of two primary colors to mix. If the user enters anything other than “red,” “blue,” or “yellow,” the program should display an error message. Otherwise, the program should display the name of the secondary color that results.
Once you have completed the program, take a screen shot of the completed functionality (including the input and the output).
Also Describe your process in developing the program in detail.
Solution:
# Declaring a list of primary colors primary_colors = ['red', 'yellow', 'blue'] # Taking input from user c1 = input('Enter the first primary color:') c2 = input('Enter the second primary color:') # Checking if entered colors are primary if not c1.lower() in primary_colors and c2.lower() in primary_colors: print('Error: The entered colors are not primary colors') # Taking an appropriate decision based on inputs else: if c1.lower() == c2.lower(): print(c1) elif c1.lower() == 'red': if c2.lower() == 'blue': print('Mixture of these two primary colors gives us the secondary color purple') if c2.lower() == 'yellow': print('Mixture of these two primary colors gives us the secondary color orange') elif c1.lower() == 'blue': if c2.lower() == 'red': print('Mixture of these two primary colors gives us the secondary color purple') if c2.lower() == 'yellow': print('Mixture of these two primary colors gives us the secondary color green') elif c1.lower() == 'yellow': if c2.lower() == 'red': print('Mixture of these two primary colors gives us the secondary color orange') if c2.lower() == 'blue': print('Mixture of these two primary colors gives us the secondary color green')
Output: