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:
When you mix red and blue, you get purple.
When you mix red and yellow, you get orange.
When you mix blue and yellow, you get green.
Design 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.
CODE:
P_1 = input("Enter a name of 1st primary color to mix:") #Asking the user to enter 1ts primary color.
P_2 = input("Enter a name of 2nd primary color to mix:") #Asking the user to enter 1ts primary color.
Primary_colors = ["red","yellow","blue"] #Assiging the primary colors.
if P_1 in Primary_colors and P_2 in Primary_colors: #Checking if user given colors matches primary colors.
#if yes..
if P_1=="red" and P_2=="yellow": #Check the input colors are red and yellow.
print(" The name of the secondary color is :'Orange'") # if yes display the respective color.
if P_1=="yellow" and P_2=="blue": #Check the input colors are blue and yellow.
print(" The name of the secondary color is :'Green'") # if yes display the respective color.
if P_1=="red" and P_2=="blue": #Check the input colors are red and blue.
print(" The name of the secondary color is :'Purple'") # if yes display the respective color.
else: #if the input colors does not match primary color.
print("Error....!") #display an error messaage .
OUTPUT:
Enter a name of 1st primary color to mix:red
Enter a name of 2nd primary color to mix:blue
The name of the secondary color is :'Purple'
Enter a name of 1st primary color to mix:black
Enter a name of 2nd primary color to mix:red
Error....!