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))
3 Answers
+ 1
What are you expecting to get?
0
What are you trying?
What is sum value you are taking? is it sum(data) ? wrong value you are taken.
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))