0

APPLE OF MY EYE TASK - HELP

What is wrong with my code??? data = [ [23, 11, 5, 14], [8, 32, 20, 5] ] color = input() #your code goes here a=[x[0] for x in data] b=[x[1] for x in data] c=[x[2] for x in data] d=[x[3] for x in data] brown = a blue = b green = c black = d brown_1 = sum(a) blue_1 = sum(b) green_1 = sum(c) black_1 = sum(d) listSum = [sum(x) for x in data] listSum2 = sum(listSum) if color == a : print (int((brown_1/listSum2)*100)) elif color == b : print (int((blue_1/listSum2)*100)) elif color == c : print (int((green_1/listSum2)*100)) elif color == d : print (int((black_1/listSum2)*100))

21st Oct 2022, 12:07 PM
stefano sartori
stefano sartori - avatar
2 Answers
0
Hi, stefano sartori ! What are you trying to do with this line in your code? a = [x[0] for x in data] This comprehension says that all datas element x are lists (or tuples or strings) and for every element x in data, you take out its first element and make a new list of it. But data is a list with just integers as element in your code, so this wont work. So if: data = ["snake", [9, 5, 0], (22, 44, 66)] a = [x[0] for x in data] Will give that: => a = ['s', 9, 22]
21st Oct 2022, 2:06 PM
Per Bratthammar
Per Bratthammar - avatar