Python Forum

Full Version: Color mixing
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
When mixed, the primary colors-red, blue, and yellow- create secondary colors- orange, green and purple. mix red and blue to get purple. mix blue and yellow to get green. mix yellow and red toget orange.User needs to enter two of the primary colors. If anything other than red ,blue or yellow is entered, the program should display an error message. If they enter two of the same color, an error message should disply. Otherwise display the new secondary
there is nothing under your link
Quote:there is nothing under your link
(Jan-27-2017, 01:26 AM)micseydel Wrote: [ -> ]You can't just provide your verbatim homework and your code, outside of code tags. You need to ask a question that helps you get unblocked, and you should use code tags when you post code (and generally you should be posting code).
print( "Enter two of the primary colors.")
print("red and blue", red and blue = purple)
print("blue and yellow", blue and yellow = green)
print("yellow and red", yellow and red = orange
     
     
if not red and blue or yellow:
    print("error message.")
elif two of the same colors:
    print("error message.")
else:
    print("secondary color.")
Between this thread and your other one, I can't help but think you are not putting any effort what so ever into the assignments.  If you are ignoring your instructor as much as you are ignoring the Admins and Mods on this forum, it is no wonder you are having difficulties.  Have you even tried to run the code you posted?  You need to go back and learn the basics of Python.  If your instructor is not getting the information to you, there are many many tutorials on Python, both in print and video out there and surely one of them will be presented in a way you will understand.  If your aim is to simply post an assignment and expect someone to complete it for you, then sadly, you have come to the wrong forum.
This code is absolutely easy to write. The difficulty itself lies in the HEX codes, the correct code guarantees the correct display of the color. Hex codes for various colors can be found at https://create.vista.com/colors/color-names/brown/.
This question has nothing to do with hex codes. It has nothing to do with color mixing. The assignment is about input verification and logic.

Your program needs to print instructions to the user and take user input. You've demonstrated you know how to print instructions. Do you know how to take user input?

Once you get user input you may need to process it to derive a result to print. Looks like you intend to do something like this:
If the two primary colors are red and blue
    print purple
else if the two primary colors are blue and yellow
    print green
else if the two primary colors are red and yellow
    print orange
else
    print error message
How do you convert this pseudo code into Python? "two primary colors" sounds like a container that can hold multiple values. Which Python types can contain more than one value?

How do you do the comparison? Are red and blue going to be the strings "red" and "blue"? What if the user types "Red" and "BLUE"? Those should be identified as primary colors. How can you make the string comparison case insensitive?

What should you do if the user enters "blue" and "blue"? These are both primary colors, and if you mix them you get blue. Should your program print "blue" or should it warn that the colors cannot be the same?