forked from RoksYz/CS1301xIII---Data-Structures
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFindColor.py
35 lines (31 loc) · 1006 Bytes
/
FindColor.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
def find_color(string):
ss = string.split('rgb')
ss = ss[1].split(',')
ss = str(ss)
ss = ss.replace("(","")
ss = ss.replace(")","")
ss = ss.replace("[","")
ss = ss.replace("]","")
ss = ss.replace(",","")
ss = ss.replace("'","")
ss = ss.split()
red_val = int(ss[0])
green_val = int(ss[1])
blue_val = int(ss[2])
if red_val == green_val and red_val == blue_val:
return "gray"
elif red_val > green_val and red_val > blue_val:
return "red"
elif blue_val > red_val and blue_val > green_val:
return "blue"
elif green_val > red_val and green_val > blue_val:
return "green"
elif red_val == green_val != blue_val:
return "yellow"
elif red_val == blue_val != green_val:
return "purple"
elif green_val == blue_val:
return "teal"
print(find_color("rgb(125, 50, 75)"))
print(find_color("rgb(0, 50, 50)"))
print(find_color("rgb(217, 217, 217)"))