0

I can not pass internal test

I need a help, I can not find mistake This is my code: data = [ [23, 11, 5, 14], [8, 32, 20, 5] ] color = input() sum = 0 total = 0 #ваш код if color == 'brown': sum = data[0][0] + data[1][0] elif color == 'blue': sum = data[1][0] + data[1][1] elif color == 'green': sum = data[2][0] + data[1][2] elif color == 'black': sum = data[3][0] + data[1][3] for n in data: for m in n: total = total + m print(int(sum/total*100))

28th Dec 2021, 6:17 AM
Lyapunov Alexander
Lyapunov Alexander - avatar
7 Respuestas
+ 4
To make it easier to understand: data = [ #brown, blue, green, black [ 23, 11, 5, 14 ], #male [ 8, 32, 20, 5 ] #female ]
28th Dec 2021, 7:07 AM
Solo
Solo - avatar
+ 5
Indexing problem. <data> only has 2 rows, but you try to access data[2][0] and data[3][0] when calculating <sum>. Those rows do not exist.
28th Dec 2021, 6:53 AM
Ipang
+ 4
To help you, need to know the task at least.
28th Dec 2021, 6:35 AM
Solo
Solo - avatar
+ 3
The 2D matrix only have two rows, but you are trying to access row 3 and row 4 that don't exist.
28th Dec 2021, 7:37 AM
Jan
Jan - avatar
+ 3
Yes, it's work. Thank you very much!
28th Dec 2021, 9:15 AM
Lyapunov Alexander
Lyapunov Alexander - avatar
+ 2
If you want to contact someone personally, you can do this through the @ symbol.
28th Dec 2021, 9:39 AM
Solo
Solo - avatar
0
I'm sorry, of course Task: You are given a 2D matrix, which represents the number of people in a room, grouped by their eye color and gender. The first row represents the male gender, while the second row represents females. The columns are the eye colors, in the following order: brown, blue, green, black: The data shows that, for example, there are 20 green eyed females in the room (2nd row, 3rd column). Our program needs to take eye color as input and output the percentage of people with that eye color in the room. Sample Input: blue Sample Output: 36
28th Dec 2021, 6:44 AM
Lyapunov Alexander
Lyapunov Alexander - avatar