Here is another way using class
#!/usr/bin/env python3
class ColorPick:
def __init__(self, color, output='just another colour'):
self.color = color
self.output = output
def Blue(self):
print("Blue, I like this colour")
def blue(self):
print("blue, I like this colour")
def white(self):
print("white, I still prefer blue")
def yellow(self):
print("yellow, this is gold colour")
def notyourcolor(self):
print(x_color, "just another color")
class Pick(ColorPick):
pass
retry = 0
while retry == 0:
count = 0
x_color = input("what color do you choose? ")
if x_color == 'blue' and count == 0:
yourcolor = Pick(x_color)
yourcolor.blue()
count = 1
elif x_color == 'Blue' and count == 0:
yourcolor = Pick(x_color)
yourcolor.Blue()
count = 1
elif x_color == 'white' and count == 0:
yourcolor = Pick(x_color)
yourcolor.white()
count = 1
elif x_color == 'yellow' and count == 0:
yourcolor = Pick(x_color)
yourcolor.yellow()
count = 1
elif count == 0:
yourcolor = Pick(x_color)
yourcolor.notyourcolor()
answer = input('do you wish to go again? Y or y for yes, any other no? ')
if answer == 'Y' or answer == 'y':
retry = 0
print('')
else:
retry = 1
print('')
print('sorry to see you leave')
/home/michael/PycharmProjects/colors.py/venv/bin/python /home/michael/PycharmProjects/colors.py/colors.py
what color do you choose? blue
blue, I like this colour
do you wish to go again? Y or y for yes, any other no? y
what color do you choose? white
white, I still prefer blue
do you wish to go again? Y or y for yes, any other no? y
what color do you choose? Blue
Blue, I like this colour
do you wish to go again? Y or y for yes, any other no? y
what color do you choose? Green
Green just another color
do you wish to go again? Y or y for yes, any other no? Y
what color do you choose? biege
biege just another color
do you wish to go again? Y or y for yes, any other no? n
sorry to see you leave
Process finished with exit code 0