In: Computer Science
The colours red, blue, and yellow are known as the primary colours because they cannot be made
by mixing other colours. When you mix two primary colours, you get one of following secondary
colour:
- Mix red and blue: purple
- Mix red and yellow: orange
- Mix blue and yellow: green
Write a function colour_mix that takes two strings as parameters as two primary colours and
returns the secondary colour. If the parameters are anything other than "red", "blue", or
"yellow", the function should return the string "Error". Save the function in a PyDev library
module named functions.py
Write a main program named t05.py that tests the function by asking the user to enter the names
of two primary colours to mix and displays the mixed colour.
A sample run:
Enter a first colour: red
Enter a second colour: blue
The mixed colour is purple.
Or
Enter a first colour: red
Enter a second colour: brown
The mixed colour is Error
• Test your program with 2 different data, other than the example.
• Copy the results to testing.txt.
please
PYTHON CODE:
#function definition
def colour_mix():
#opening file
f=open("testing.txt","w")
#taking inputs
a=input("Enter a first colour: ")
b=input("Enter a second colour: ")
#writing input colours to file
f.write(f"First colour: {a}\nSecond colour: {b}\n\n")
#condition for purple colour
if (a=="blue" and b=="red") or (b=="blue" and a=="red"):
print("The mixed colour is purple.")
f.write("The mixed colour is purple.") #writing to file
#condition for orange colour
elif (a=="yellow" and b=="red") or (b=="yellow" and a=="red"):
print("The mixed colour is orange.")
f.write("The mixed colour is orange.") #writing to file
#condition for green colour
elif (a=="yellow" and b=="blue") or (b=="yellow" and a=="blue"):
print("The mixed colour is green.")
f.write("The mixed colour is green.") #writing to file
#for wrong input
else:
print("The mixed colour is Error.")
f.write("The mixed colour is Error.") #writing to file
#main
#function call
colour_mix()
SAMPLE RUNS:
output file: