🚧Summaries For Lessons 24+ Are Still Work In Progress!

“Whoever is patient has great understanding…" Proverbs 14:29

Exercise: Mis Colors Game

Description here...

Exercise: Mis Colors Game

Description here...

Exercise: Mis Colors Game

Description here...

- Practice writing Python
- Create Logical Statements Yourself
- Create a fun Color Mixing Game

H2

You're already learning a lot about Python, and now let's make a simple exercise. Afterall, Practice is the best way to learn programming!

In this lesson, we'll write a fun script where we provide 2 colors and get the result of mixing them. So if we provide Yellow + Red we should see Orange as a result. I think it's quite fn and you get to practice Python.

Before we begin, make sure you try to do it on your own. And don't worry if you see errors or get stuck. That's part of the learning process.

Ready? Set. Code!

Pseudo-Code

Before starting to code, it's best to brainstorm and layout all the steps. You can write it on the paper, or use comments inside your script. It's often called 'Pseudo-Code' or 'Skeleton Code'.

So for this script:

# Step 1 - User Input

# Step 2 - Calculate Colors

# Step 3 - Display Results
# Step 1 - User Input

# Step 2 - Calculate Colors

# Step 3 - Display Results
# Step 1 - User Input

# Step 2 - Calculate Colors

# Step 3 - Display Results

In this case it's very simple, but you're building a habit so you can do the same with 10-20 steps too.

Get User Input

Let's begin with getting user input():

#🙋‍♂️ User Input
color1 = input('Enter First Color (red, blue, yellow): ').lower()
color2 = input('Enter Second Color (red, blue, yellow): ').lower()
#🙋‍♂️ User Input
color1 = input('Enter First Color (red, blue, yellow): ').lower()
color2 = input('Enter Second Color (red, blue, yellow): ').lower()
#🙋‍♂️ User Input
color1 = input('Enter First Color (red, blue, yellow): ').lower()
color2 = input('Enter Second Color (red, blue, yellow): ').lower()

💡Don't forget to apply .lower() to avoid issues with lower and upper case comparisons.

Logic - Calculate New Color

The logic is very simple. We are going to check color_1 and color_2 and then print the resulting color. But keep in mind that your combination can be reversed, so you'll need multiple if statements to do it right.

This starts to work, but code looks really ugly🤮. But we can fix it.

To simplify the if-statement we need to combine colors in a list, then we can check if colors are inside with membership-operators. This will make it look much nicer:

#🙋‍♂️ User Input
color1 = input('Enter First Color (red, blue, yellow): ').lower()
color2 = input('Enter Second Color (red, blue, yellow): ').lower()
colors = [color1, color2] # Combine Colors

#🎨 Calculate Color
if 'red' in colors and 'blue' in colors:
    print('Purple')
#🙋‍♂️ User Input
color1 = input('Enter First Color (red, blue, yellow): ').lower()
color2 = input('Enter Second Color (red, blue, yellow): ').lower()
colors = [color1, color2] # Combine Colors

#🎨 Calculate Color
if 'red' in colors and 'blue' in colors:
    print('Purple')
#🙋‍♂️ User Input
color1 = input('Enter First Color (red, blue, yellow): ').lower()
color2 = input('Enter Second Color (red, blue, yellow): ').lower()
colors = [color1, color2] # Combine Colors

#🎨 Calculate Color
if 'red' in colors and 'blue' in colors:
    print('Purple')

This way you don't care the order of colors that user provides. It will work both ways.

Sign-Up For Future Updates✨

Be among the first people to hear about
New Python Courses or Useful Resources!

Once there's enough demand I might start a Python Newsletter
with even more Tips and Tricks to help you learn it better!


Want To Donate? Click here.

Sign-Up For Future Updates✨

Be among the first people to hear about
New Python Courses or Useful Resources!

Once there's enough demand I might start a Python Newsletter
with even more Tips and Tricks to help you learn it better!


Want To Donate? Click here.

Sign-Up For Future Updates✨

Be among the first people to hear about
New Python Courses or Useful Resources!

Once there's enough demand I might start a Python Newsletter
with even more Tips and Tricks to help you learn it better!


Want To Donate? Click here.

Improve Print Statements

Now, let's add more color combinations and make our print statements spicer 🧂.

#🙋‍♂️ User Input
color1 = input('Enter First Color (red, blue, yellow): ').lower()
color2 = input('Enter Second Color (red, blue, yellow): ').lower()
colors = [color1, color2]

print('-'*50)
print(f"🥼 Let's Mix {color1} + {color2}\n")

#🎨 Calculate Colors
if color1 == color2:
    print("🎨 You're mixing the same color!")

elif 'red' in colors and 'blue' in colors:
    print(f'🧪{color1} + 🧪{color2} = Purple 💜.')

elif 'red' in colors and 'yellow' in colors:
    print(f'🧪{color1} + 🧪{color2} = Orange 🧡.')

elif 'blue' in colors and 'yellow' in colors:
    print(f'🧪{color1} + 🧪{color2} = Green 💚.')

else:
    print('❌ Invalid Color Combination. \nPlease use Red, Blue or Yellow.')
#🙋‍♂️ User Input
color1 = input('Enter First Color (red, blue, yellow): ').lower()
color2 = input('Enter Second Color (red, blue, yellow): ').lower()
colors = [color1, color2]

print('-'*50)
print(f"🥼 Let's Mix {color1} + {color2}\n")

#🎨 Calculate Colors
if color1 == color2:
    print("🎨 You're mixing the same color!")

elif 'red' in colors and 'blue' in colors:
    print(f'🧪{color1} + 🧪{color2} = Purple 💜.')

elif 'red' in colors and 'yellow' in colors:
    print(f'🧪{color1} + 🧪{color2} = Orange 🧡.')

elif 'blue' in colors and 'yellow' in colors:
    print(f'🧪{color1} + 🧪{color2} = Green 💚.')

else:
    print('❌ Invalid Color Combination. \nPlease use Red, Blue or Yellow.')
#🙋‍♂️ User Input
color1 = input('Enter First Color (red, blue, yellow): ').lower()
color2 = input('Enter Second Color (red, blue, yellow): ').lower()
colors = [color1, color2]

print('-'*50)
print(f"🥼 Let's Mix {color1} + {color2}\n")

#🎨 Calculate Colors
if color1 == color2:
    print("🎨 You're mixing the same color!")

elif 'red' in colors and 'blue' in colors:
    print(f'🧪{color1} + 🧪{color2} = Purple 💜.')

elif 'red' in colors and 'yellow' in colors:
    print(f'🧪{color1} + 🧪{color2} = Orange 🧡.')

elif 'blue' in colors and 'yellow' in colors:
    print(f'🧪{color1} + 🧪{color2} = Green 💚.')

else:
    print('❌ Invalid Color Combination. \nPlease use Red, Blue or Yellow.')

Now we're getting somewhere!

  • Combine User Inputs

  • Check Same Colors

  • Check Different Colors

  • Ensure only allowed colors used

Here's how it looks in the console:

Improve Same Color Combination

Since we're practicing logic, let's add another statement to get the right emoji for the same colors. For that we just need to check what is the color1 and return the right emoji.

if color1 == color2:
    emoji = None
    if color1 == 'red':
        emoji = '❤️'
    elif color1 == 'blue':
        emoji = '💙'
    elif color1 == 'yellow':
        emoji = '💛'

    print("🎨 You're mixing the same color!")
    print(f'🧪{color1} + 🧪{color2} = {color1} {emoji}.')
if color1 == color2:
    emoji = None
    if color1 == 'red':
        emoji = '❤️'
    elif color1 == 'blue':
        emoji = '💙'
    elif color1 == 'yellow':
        emoji = '💛'

    print("🎨 You're mixing the same color!")
    print(f'🧪{color1} + 🧪{color2} = {color1} {emoji}.')
if color1 == color2:
    emoji = None
    if color1 == 'red':
        emoji = '❤️'
    elif color1 == 'blue':
        emoji = '💙'
    elif color1 == 'yellow':
        emoji = '💛'

    print("🎨 You're mixing the same color!")
    print(f'🧪{color1} + 🧪{color2} = {color1} {emoji}.')

Great, now we can display the right color emoji in the console if color1 == color2:

Final Code:

Let's bring it all together:

# 🧑‍🎨Let's Mix Up Some Colors! 🎨🖌️

#🙋‍♂️ User Input
color1 = input('Enter First Color (red, blue, yellow): ').lower()
color2 = input('Enter Second Color (red, blue, yellow): ').lower()
colors = [color1, color2]

print('-'*50)
print(f"🥼 Let's Mix {color1} + {color2}\n")

#🎨 Calculate New Color
if color1 == color2:
    emoji = None
    if color1 == 'red':
        emoji = '❤️'
    elif color1 == 'blue':
        emoji = '💙'
    elif color1 == 'yellow':
        emoji = '💛'

    print("🎨 You're mixing the same color!")
    print(f'🧪{color1} + 🧪{color2} = {color1} {emoji}.')

elif 'red' in colors and 'blue' in colors:
    print(f'🧪{color1} + 🧪{color2} = Purple 💜.')

elif 'red' in colors and 'yellow' in colors:
    print(f'🧪{color1} + 🧪{color2} = Orange 🧡.')

elif 'blue' in colors and 'yellow' in colors:
    print(f'🧪{color1} + 🧪{color2} = Green 💚.')

else:
    print('❌ Invalid Color Combination. \nPlease use Red, Blue or Yellow.')
# 🧑‍🎨Let's Mix Up Some Colors! 🎨🖌️

#🙋‍♂️ User Input
color1 = input('Enter First Color (red, blue, yellow): ').lower()
color2 = input('Enter Second Color (red, blue, yellow): ').lower()
colors = [color1, color2]

print('-'*50)
print(f"🥼 Let's Mix {color1} + {color2}\n")

#🎨 Calculate New Color
if color1 == color2:
    emoji = None
    if color1 == 'red':
        emoji = '❤️'
    elif color1 == 'blue':
        emoji = '💙'
    elif color1 == 'yellow':
        emoji = '💛'

    print("🎨 You're mixing the same color!")
    print(f'🧪{color1} + 🧪{color2} = {color1} {emoji}.')

elif 'red' in colors and 'blue' in colors:
    print(f'🧪{color1} + 🧪{color2} = Purple 💜.')

elif 'red' in colors and 'yellow' in colors:
    print(f'🧪{color1} + 🧪{color2} = Orange 🧡.')

elif 'blue' in colors and 'yellow' in colors:
    print(f'🧪{color1} + 🧪{color2} = Green 💚.')

else:
    print('❌ Invalid Color Combination. \nPlease use Red, Blue or Yellow.')
# 🧑‍🎨Let's Mix Up Some Colors! 🎨🖌️

#🙋‍♂️ User Input
color1 = input('Enter First Color (red, blue, yellow): ').lower()
color2 = input('Enter Second Color (red, blue, yellow): ').lower()
colors = [color1, color2]

print('-'*50)
print(f"🥼 Let's Mix {color1} + {color2}\n")

#🎨 Calculate New Color
if color1 == color2:
    emoji = None
    if color1 == 'red':
        emoji = '❤️'
    elif color1 == 'blue':
        emoji = '💙'
    elif color1 == 'yellow':
        emoji = '💛'

    print("🎨 You're mixing the same color!")
    print(f'🧪{color1} + 🧪{color2} = {color1} {emoji}.')

elif 'red' in colors and 'blue' in colors:
    print(f'🧪{color1} + 🧪{color2} = Purple 💜.')

elif 'red' in colors and 'yellow' in colors:
    print(f'🧪{color1} + 🧪{color2} = Orange 🧡.')

elif 'blue' in colors and 'yellow' in colors:
    print(f'🧪{color1} + 🧪{color2} = Green 💚.')

else:
    print('❌ Invalid Color Combination. \nPlease use Red, Blue or Yellow.')

Happy Coding!

🙋‍♂️ See you in the next lesson.
- EF

Happy Coding!

🙋‍♂️ See you in the next lesson.
- EF

Happy Coding!

🙋‍♂️ See you in the next lesson.
- EF

Now it's your turn.

I hope that you've already tried to make this script on your own without looking at my code or full tutorial. But either way, make sure to try this code in your own script.

You won't become python expert by watching me code. You need to write code yourself too. And it's also best if you're going to experiment, make changes and learn something new along the way.

⌨️ Happy Coding!

⌨️ Happy Coding!

⌨️ Happy Coding!

If you have any questions, leave them in the YouTube Comments.

If you have any questions, leave them in the YouTube Comments.

If you have any questions, leave them in the YouTube Comments.

Have a Question?

Have a Question?

Have a Question?

Sign-Up For Future Updates✨

Be among the first people to hear about
New Python Courses or Useful Resources!

Once there's enough demand I might start a Python Newsletter
with even more Tips and Tricks to help you learn it better!


Want To Donate? Click here.

Sign-Up For Future Updates✨

Be among the first people to hear about
New Python Courses or Useful Resources!

Once there's enough demand I might start a Python Newsletter
with even more Tips and Tricks to help you learn it better!


Want To Donate? Click here.

Sign-Up For Future Updates✨

Be among the first people to hear about
New Python Courses or Useful Resources!

Once there's enough demand I might start a Python Newsletter
with even more Tips and Tricks to help you learn it better!


Want To Donate? Click here.

PS. Python can change your career and how you think about problems.
Be Careful 🙂

PS. Python can change your career and how you think about problems.
Be Careful 🙂

PS. Python can change your career and how you think about problems.
Be Careful 🙂

Sposored by LearnRevitAPI.com