0

Please what’s wrong with this code??

data = [ [23, 11, 5, 14], [8, 32, 20, 5] ] color = input() #your code goes here sum = 23+11+5+25+52 if color == "brown": print(int((data[0][0]+data[1][0])/(sum)*100)) elif color == "blue": print(int((data[0][1]+data[1][1])/(sum)*100)) elif color == "green": print(int((data[0][2]+ data[1][2])/(sum)*100)) else : print(int((data[0][3]+data[1][3])/(sum)*100))

14th Jun 2022, 3:32 PM
Benjamin Olusoji
Benjamin Olusoji - avatar
3 Answers
+ 1
What are you expecting to get?
14th Jun 2022, 4:01 PM
Mustafa A
Mustafa A - avatar
0
What are you trying? What is sum value you are taking? is it sum(data) ? wrong value you are taken.
14th Jun 2022, 4:03 PM
Jayakrishna 🇼🇳
0
I don't know what where you trying to do, but as I rode your code I got this attempt to fix it: data = [ [23, 11, 5, 14], [8, 32, 20, 5] ] color = input() # using functions rather manual s = sum(map(sum,data)) # the formula result = lambda x: (data[0][x]+data[1][x])/s*100 try: # trying to get index, which with be used as argument to `result` print(result(['brown','blue','green'].index(color))) except: # if .index throws error: color not listed print(result(3))
14th Jun 2022, 9:17 PM
Ervis Meta
Ervis Meta - avatar