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

.

Solutions

Expert Solution

code:

functions.py:

#defining the function colour mix
def colour_mix(col1,col2):
   #if color is red and blue
   if ((col1=="red" and col2=="blue") or(col1=="blue" and col2=="red")):
       res="purple"
   #if color is red and yellow
   elif ((col1=="red" and col2=="yellow") or(col1=="yellow" and col2=="red")):
       res="orange"
   #if color is blue and yellow
   elif ((col1=="blue" and col2=="yellow") or(col1=="yellow" and col2=="blue")):
       res="green"
   #if invalid input
   else:
       res="error"
   #returning res
   return res   

t05.py

#importing the module
import functions
#taking inputs from user
color1=input("Enter Color 1: ")
color2=input("Enter color 2 :" )
#storing the return value in result from calling the function
result=functions.colour_mix(color1,color2)
#printing result
print(result)

Output:

Code Screenshot:

Code Snippet:

functions.py

#defining the function colour mix
def colour_mix(col1,col2):
        #if color is red and blue
        if ((col1=="red" and col2=="blue") or(col1=="blue" and col2=="red")):
                res="purple"
        #if color is red and yellow
        elif ((col1=="red" and col2=="yellow") or(col1=="yellow" and col2=="red")):
                res="orange"
        #if color is blue and yellow
        elif ((col1=="blue" and col2=="yellow") or(col1=="yellow" and col2=="blue")):
                res="green"
        #if invalid input
        else:
                res="error"
        #returning res
        return res      

t05.py

#importing the module
import functions
#taking inputs from user
color1=input("Enter Color 1: ")
color2=input("Enter color 2 :" )
#storing the return value in result from calling the function
result=functions.colour_mix(color1,color2)
#printing result
print(result)

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",...
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