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",...
PYTHON PROGRAMMING The colors red, blue, and yellow are known as the primary colors because they...
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: Red and blue = purple Red and yellow = orange Blue and yellow = green 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...
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...
<!DOCTYPE html> <html> <body> <script> // // The colors red, blue, and yellow are known as...
<!DOCTYPE html> <html> <body> <script> // // 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...
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?
The following shows the French translation for some colours: English French red rouge orange orange yellow...
The following shows the French translation for some colours: English French red rouge orange orange yellow jaune green vert blue bleu Create a program ColourTranslator that displays the French translation of the English colour obtained from the user. E.g.: System: Enter a colour in English: User: red System: The French word for red is rouge. Include a default case that handles input that is not on the list. e.g. System: Enter a colour in English User: purple System: Sorry, purple...
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.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT