having an issua comparing comparing Strings @ python
Question: Probably there is an easier way to do this, but i read there is no Switch/case
in Python. I wanted to ask the user, to introduce a name of a color, and after
calling the function that should take care of that, it should return the color
code in RGB. My if statements should also accept when the first letter or the
whole word is in capital.

The wierd thing that is happening to me is, i keep geting results on my
console that makes no sence, i am SURE that there is (somewhere) a mystake
from me!

After puting the same input, exacly the same word, the results on the console
are not the same.

AT the moment this is my exact code.

    
    
    import pygame
    import sys
    
    from pygame.locals import *
    
    White =(255, 0, 0)
    Black = (0, 0, 0)
    
    Red = (255, 0, 0)
    Green = (0, 255, 0)
    Blue = (0, 0, 255)
    
    Yellow = (255, 255, 0)
    Cyan = (0, 255, 255)
    Purple = (255, 0, 255)
    
    
    def set_display():
        pygame.init()
        Display = pygame.display.set_mode((400, 300))
        pygame.display.set_caption('Seda\'s drawing game')
    
    
    def get_color():
        print('Please introduce one of the following colors')
        print(' \n White \n Black \n Red \n Green \n Blue \n Yellow \n Cyan \n Purple')
        color = input()
        print (color)
        if (color == 'Black') or (color == 'BLACK') or (color == 'black'):
            return Black
        elif (color == 'White') or (color == 'WHITE') or (color == 'white'):
            return White
        elif (color == 'Red') or (color == 'RED') or (color == 'red'):
            return Red
        elif (color == 'Green') or (color == 'GREEN') or (color == 'green'):
            return Green
        elif (color == 'Blue') or (color == 'BLUE') or (color == 'blue'):
            return Blue
        elif (color == 'Yellow') or (color == 'YELLOW') or (color == 'yellow'):
            return Yellow
        elif (color == 'Purple') or (color == 'PURPLE') or (color == 'purple'):
            return Purple
        elif (color == 'Cyan') or (color == 'CYAN') or (color == 'cyan'):
            return Cyan
    
    
    
    
    
    while True:
    
    #    set_display()
    #    for event in pygame.event.get():
    #       if event.type == QUIT:
    #           pygame.quit()
    #           sys.exit()
    
    
        final_color = get_color()
        print ( get_color())
        print (final_color)
    

Console output:

    
    
    Please introduce one of the following colors
    
     White 
     Black 
     Red 
     Green 
     Blue 
     Yellow 
     Cyan 
     Purple
    white
    white
    Please introduce one of the following colors
    
     White 
     Black 
     Red 
     Green 
     Blue 
     Yellow 
     Cyan 
     Purple
    white
    white
    (255, 0, 0)
    (255, 0, 0)
    Please introduce one of the following colors
    
     White 
     Black 
     Red 
     Green 
     Blue 
     Yellow 
     Cyan 
     Purple
    White
    White
    Please introduce one of the following colors
    
     White 
     Black 
     Red 
     Green 
     Blue 
     Yellow 
     Cyan 
     Purple
    White
    White
    (255, 0, 0)
    (255, 0, 0)
    Please introduce one of the following colors
    
     White 
     Black 
     Red 
     Green 
     Blue 
     Yellow 
     Cyan 
     Purple
    WHITE
    WHITE
    Please introduce one of the following colors
    
     White 
     Black 
     Red 
     Green 
     Blue 
     Yellow 
     Cyan 
     Purple
    WHITE
    WHITE
    (255, 0, 0)
    (255, 0, 0)
    Please introduce one of the following colors
    
     White 
     Black 
     Red 
     Green 
     Blue 
     Yellow 
     Cyan 
     Purple
    

it seems every 2 times i write something, if gives me back the color RGB code.

what i keep finding hard to understand, is why this:

    
    
        final_color = get_color()
        print ( get_color())
        print (final_color)
    

is not showing the exact same thing.

Thanks for the help guys

EDDIT1: i found out using extras on those prints, that he is not getting to
those 2 last prints. Still to know why..

EDDIT2: i notice my own error.. saying white is (255,0,0) :D


Answer: The way you return the color could be simplified a lot by doing this. It also
fixes your bug.

    
    
    White =(255, 0, 0)
    Black = (0, 0, 0)
    
    Red = (255, 0, 0)
    Green = (0, 255, 0)
    Blue = (0, 0, 255)
    
    Yellow = (255, 255, 0)
    Cyan = (0, 255, 255)
    Purple = (255, 0, 255)
    
    colours = {
        'white' : White,
        'black' : Black,
        'red' : Red,
        'green' : Green,
        'blue' : Blue,
        'yellow' : Yellow,
        'cyan' : Cyan,
        'purple' : Purple
    }
    
    def get_colour():
        print('Please introduce one of the following colours')
        for key in sorted(colours):
            print(key.capitalize())
        colour = input()
        return colours[colour.lower()]
    
    if __name__ == '__main__': #just added for preference
        while True:
            final_colour = get_colour()
            print(final_colour)
    

You should familiarize yourself with `lists`, `dictionaries`, and some basic
Python functions. They make life a lot easier!

<https://docs.python.org/3/tutorial/datastructures.html>

P.S. Your `Red` and `White` rgb values are the same.

