Question

In: Computer Science

The colours red, blue, and yellow are known as the primary colours because they cannot be...

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

Solutions

Expert Solution

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:


Related Solutions

The colours red, blue, and yellow are known as the primary colours because they cannot be...
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...
Brian is selling balloons in 8 different colours: red, pink, yellow, blue, green, purple, black and...
Brian is selling balloons in 8 different colours: red, pink, yellow, blue, green, purple, black and silver. How many different selections of 16 helium balloons can be purchased if the shop has at least 16 balloons of each colour in stock? How many different selections of 16 helium balloons can be purchased if you buy at least 3 red balloons and at least 5 yellow balloons, and the shop has at least 16 balloons of each colour in stock? How...
A shop sells helium balloons in eight different colours: red, pink, yellow, blue, green, purple, black...
A shop sells helium balloons in eight different colours: red, pink, yellow, blue, green, purple, black and silver. (a) How many different selections of 16 helium balloons can be purchased if the shop has at least 16 balloons of each colour in stock? (b) How many different selections of 16 helium balloons can be purchased if you buy at least 3 red balloons and at least 5 yellow balloons, and the shop has at least 16 balloons of each colour...
Language C++ Ask the user to enter the name of one primary color (red, blue, yellow)...
Language C++ Ask the user to enter the name of one primary color (red, blue, yellow) and a second primary color that is different from the first. Based on the user's entries, figure out what new color will be made when mixing those two colors. Use the following guide: red and blue make purple blue and yellow make green yellow and red make orange If the user enters anything that is outside one of the above combinations, return an error...
What is the probability of drawing, in order, 2 red, 1 blue, and 2 yellow marbles if a bag contains 4 yellow, 5 red, and 6 blue marbles?
What is the probability of drawing, in order, 2 red, 1 blue, and 2 yellow marbles if a bag contains 4 yellow, 5 red, and 6 blue marbles?
For a certain​ candy, 55​% of the pieces are​ yellow, 1515​% are​ red, 55​% are​ blue,...
For a certain​ candy, 55​% of the pieces are​ yellow, 1515​% are​ red, 55​% are​ blue, 2020​% are​ green, and the rest are brown. ​a) If you pick a piece at​ random, what is the probability that it is​ brown? it is yellow or​ blue? it is not​ green? it is​ striped? ​b) Assume you have an infinite supply of these candy pieces from which to draw. If you pick three pieces in a​ row, what is the probability that...
An urn has marbles of red, blue, and yellow. There are seven marbles of each of...
An urn has marbles of red, blue, and yellow. There are seven marbles of each of the three colors. The experiment consists of drawing a single, random marble from the urn. Define a random variable X by X(s) = -1 if the marble has red 0, if the marble has blue +1, if the marble has yellow 54 random samples of X are taken. Approximate the probability that the mean of the sample is between 0 and 1/20.
Twelve chairs are to be painted. The available colors are Red, Blue, Green, and Yellow, and...
Twelve chairs are to be painted. The available colors are Red, Blue, Green, and Yellow, and every chair must be painted with one color. Assuming that all coloring schemes are equally likely, what is the probability that one color is not used and there are at least two chairs of every other color ? (The answer is 0.25) Can anyone explain to me why ?
For a certain​ candy, 15​% of the pieces are​ yellow, 10​% are​ red, 15​% are​ blue,...
For a certain​ candy, 15​% of the pieces are​ yellow, 10​% are​ red, 15​% are​ blue, 20​% are​ green, and the rest are brown. ​a) If you pick a piece at​ random, what is the probability that it is​ brown? it is yellow or​ blue? it is not​ green? it is​ striped? ​b) Assume you have an infinite supply of these candy pieces from which to draw. If you pick three pieces in a​ row, what is the probability that...
For a certain candy, 15% of the pieces are yellow, 20% are red, 20% are blue,...
For a certain candy, 15% of the pieces are yellow, 20% are red, 20% are blue, 5% are green, and the rest are brown. a) If you pick a piece at random, what is the probability that it is​ brown? it is yellow or​ blue? it is not​ green? it is​ striped? b) Assume you have an infinite supply of these candy pieces from which to draw. If you pick three pieces in a​ row, what is the probability that...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT