Colors in classes was 285 lines. This version is shortened to 50 lines. I created a 2d list for the variables. I created a print and main class.
ColorTypes.py
class ColorTypes:
a = b = c = d = e = f = g = ''
def choice(self, color, prisec='primary', primaryone='Red', primarytwo='None', secondaryone='None',
secondarytwo='None', complimentary='None', output='This is a primary color'):
ColorTypes.a = color
ColorTypes.b = prisec
ColorTypes.c = primaryone
ColorTypes.d = primarytwo
ColorTypes.e = secondaryone
ColorTypes.f = complimentary
class print_color(ColorTypes):
def __init__(self):
print('This is the color', ColorTypes.a)
print(ColorTypes.a, 'is a', ColorTypes.b, 'color', 'and its complimentary color is', ColorTypes.f)
if ColorTypes.b == 'primary':
print('Primary colors cannot be mixed from other colors')
if ColorTypes.b == 'secondary':
print(ColorTypes.c, 'and', ColorTypes.d, 'makes', ColorTypes.a)
if ColorTypes.b == 'tertiary':
print(ColorTypes.c, 'and', ColorTypes.e, 'makes', ColorTypes.a)
print('')
def main():
colorlist = [['red', 'primary', 'None', 'None', 'None', 'None', 'green'],
['blue', 'primary', 'None', 'None', 'None', 'None', 'orange'],
['yellow', 'primary', 'None', 'None', 'None', 'None', 'purple'],
['orange', 'secondary', 'red', 'yellow', 'None', 'None', 'blue'],
['purple', 'secondary', 'blue', 'red', 'None', 'None', 'yellow'],
['green', 'secondary', 'blue', 'yellow', 'None', 'None', 'yellow'],
['redpurple', 'tertiary', 'red', 'none', 'purple', 'None', 'yellow green'],
['orangered', 'tertiary', 'red', 'none', 'orange', 'None', 'blue green'],
['orangeyellow', 'tertiary', 'yellow', 'none', 'orange', 'None', 'blue purple'],
['yellowgreen', 'tertiary', 'yellow', 'none', 'green', 'None', 'red purple'],
['bluegreen', 'tertiary', 'blue', 'none', 'green', 'None', 'orange red'],
['bluepurple', 'tertiary', 'blue', 'none', 'purple', 'None', 'orange yellow']
]
length = len(colorlist)
ob = ColorTypes()
x = 0
while x < length:
ob.choice(colorlist[x][0], colorlist[x][1], colorlist[x][2], colorlist[x][3], colorlist[x][4],
colorlist[x][5], colorlist[x][6])
print_color()
x += 1
if __name__ == "__main__":
main()
/home/michael/PycharmProjects/colors.py/venv/bin/python /home/michael/PycharmProjects/colors.py/Color_print.py
This is the color red
red is a primary color and its complimentary color is green
Primary colors cannot be mixed from other colors
This is the color blue
blue is a primary color and its complimentary color is orange
Primary colors cannot be mixed from other colors
This is the color yellow
yellow is a primary color and its complimentary color is purple
Primary colors cannot be mixed from other colors
This is the color orange
orange is a secondary color and its complimentary color is blue
red and yellow makes orange
This is the color purple
purple is a secondary color and its complimentary color is yellow
blue and red makes purple
This is the color green
green is a secondary color and its complimentary color is yellow
blue and yellow makes green
This is the color redpurple
redpurple is a tertiary color and its complimentary color is yellow green
red and purple makes redpurple
This is the color orangered
orangered is a tertiary color and its complimentary color is blue green
red and orange makes orangered
This is the color orangeyellow
orangeyellow is a tertiary color and its complimentary color is blue purple
yellow and orange makes orangeyellow
This is the color yellowgreen
yellowgreen is a tertiary color and its complimentary color is red purple
yellow and green makes yellowgreen
This is the color bluegreen
bluegreen is a tertiary color and its complimentary color is orange red
blue and green makes bluegreen
This is the color bluepurple
bluepurple is a tertiary color and its complimentary color is orange yellow
blue and purple makes bluepurple
Process finished with exit code 0
Color_print.py
#!/usr/bin/env python3
class ColorTypes:
a = b = c = d = e = f = g = ''
def choice(self, color, prisec='primary', primaryone='Red', primarytwo='None', secondaryone='None',
secondarytwo='None', complimentary='None', output='This is a primary color'):
ColorTypes.a = color
ColorTypes.b = prisec
ColorTypes.c = primaryone
ColorTypes.d = primarytwo
ColorTypes.e = secondaryone
ColorTypes.f = complimentary
class print_color(ColorTypes):
def __init__(self):
print('This is the color', ColorTypes.a)
print(ColorTypes.a, 'is a', ColorTypes.b, 'color', 'and its complimentary color is', ColorTypes.f)
if ColorTypes.b == 'primary':
print('Primary colors cannot be mixed from other colors')
if ColorTypes.b == 'secondary':
print(ColorTypes.c, 'and', ColorTypes.d, 'makes', ColorTypes.a)
if ColorTypes.b == 'tertiary':
print(ColorTypes.c, 'and', ColorTypes.e, 'makes', ColorTypes.a)
print('')
def main():
colorlist = [['red', 'primary', 'None', 'None', 'None', 'None', 'green'],
['blue', 'primary', 'None', 'None', 'None', 'None', 'orange'],
['yellow', 'primary', 'None', 'None', 'None', 'None', 'purple'],
['orange', 'secondary', 'red', 'yellow', 'None', 'None', 'blue'],
['purple', 'secondary', 'blue', 'red', 'None', 'None', 'yellow'],
['green', 'secondary', 'blue', 'yellow', 'None', 'None', 'yellow'],
['redpurple', 'tertiary', 'red', 'none', 'purple', 'None', 'yellow green'],
['orangered', 'tertiary', 'red', 'none', 'orange', 'None', 'blue green'],
['orangeyellow', 'tertiary', 'yellow', 'none', 'orange', 'None', 'blue purple'],
['yellowgreen', 'tertiary', 'yellow', 'none', 'green', 'None', 'red purple'],
['bluegreen', 'tertiary', 'blue', 'none', 'green', 'None', 'orange red'],
['bluepurple', 'tertiary', 'blue', 'none', 'purple', 'None', 'orange yellow']
]
length = len(colorlist)
ob = ColorTypes()
x = 0
while x < length:
ob.choice(colorlist[x][0], colorlist[x][1], colorlist[x][2], colorlist[x][3], colorlist[x][4],
colorlist[x][5], colorlist[x][6])
print_color()
x += 1
if __name__ == "__main__":
main() Colors.py
#!/usr/bin/env python3
class ColorPick:
def __init__(self, color, output='just another color'):
self.color = color
self.output = output
def Blue(self):
print("Blue, I like this color")
def blue(self):
print("blue, I like this color")
def white(self):
print("white, I still prefer blue")
def yellow(self):
print("yellow, this is gold color")
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')
print('')
PrimarySecondary.py
#!/usr/bin/env python3
class Primary:
def __init__(self, color, output='I am a primary color'):
self.color = color
self.output = output
def Blue(self):
print('Blue is a primary color')
def Red(self):
print('Red is a primary color')
def Yellow(self):
print('Yellow is a primary color')
class Secondary:
def __init__(self, color, output='I am a primary color'):
self.color = color
self.output = output
def Orange(self):
print('Orange is a secondary color')
print('Red and yellow makes orange')
print('')
def Green(self):
print('Green is a secondary color')
print('Red and blue makes green')
print('')
def Purple(self):
print('Purple is a secondary color')
print('Red and blue makes purple')
print('')
class PriPick(Primary):
pass
class SecPick(Secondary):
pass
Primary = PriPick('Red')
Primary.Red()
Primary = PriPick('Blue')
Primary.Blue()
Primary = PriPick('Yellow')
Primary.Yellow()
print('')
Secondary = SecPick('Orange')
Secondary.Orange()
Secondary = SecPick('Green')
Secondary.Green()
Secondary = SecPick('Purple')
Secondary.Purple()