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))
7 odpowiedzi
+ 4
To make it easier to understand:
data = [
#brown, blue, green, black
[ 23, 11, 5, 14 ], #male
[ 8, 32, 20, 5 ] #female
]
+ 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.
+ 4
To help you, need to know the task at least.
+ 3
The 2D matrix only have two rows, but you are trying to access row 3 and row 4 that don't exist.
+ 3
Yes, it's work. Thank you very much!
+ 2
If you want to contact someone personally, you can do this through the @ symbol.
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