+ 1

What's wrong in this code ?

The goal : output the % of people who have same eyes. Example : Input : Brown Output : 26% ( of 118 persons , 23 men with brown eyes + 8 girl with brown eyes ) data = [ [23, 11, 5, 14], [8, 32, 20, 5] ] total = 23 + 11 + 5 + 14 + 8 + 32 + 20 + 5 color = input() #your code goes here if color == "brown": print (int((data[0,0]+data[1,0])/total*100)) elif color == "blue": print (int((data[0,1]+data[1,1])/total*100)) elif color == "green" : print (int((data[0,2]+data[1,2])/total*100)) else : print (int((data[0,3]+data[1,3])/total*100))

28th May 2023, 6:01 PM
Remi TRAN VAN LIEU
Remi TRAN VAN LIEU - avatar
11 Respostas
+ 7
Lamron , the percentage sign is *not* required here. the sample output is without it.
29th May 2023, 8:48 AM
Lothar
Lothar - avatar
+ 7
Евгений , what tutorial are your talking about? i tested it in *python data structures*.
30th May 2023, 2:28 PM
Lothar
Lothar - avatar
+ 6
Евгений , this question is from a sololearn tutorial. use this link to get there: https://www.sololearn.com/course/JUMP_LINK__&&__Python__&&__JUMP_LINK-Data-Structures > then go to chapter *lists*. > there you can find the code coach exercise named: 9.2 *apple of my eye* > read the instructions ...
30th May 2023, 6:15 PM
Lothar
Lothar - avatar
+ 5
Hazem Hadj Ahmed Pls avoid giving finished code as answer, because it makes the OP skip the most important part of learning. Prefer giving hints for the OP to find the solution instead.
29th May 2023, 10:46 AM
Emerson Prado
Emerson Prado - avatar
+ 3
There are a couple of issues in the code provided. Here's the corrected code: data = [ [23, 11, 5, 14], [8, 32, 20, 5] ] total = 23 + 11 + 5 + 14 + 8 + 32 + 20 + 5 color = input() if color == "brown": print(int((data[0][0] + data[1][0]) / total * 100)) elif color == "blue": print(int((data[0][1] + data[1][1]) / total * 100)) elif color == "green": print(int((data[0][2] + data[1][2]) / total * 100)) else: print(int((data[0][3] + data[1][3]) / total * 100))
28th May 2023, 8:57 PM
Hazem Hadj Ahmed
Hazem Hadj Ahmed - avatar
+ 2
You didn't add the percentage sign as shown in the sample output.
28th May 2023, 6:03 PM
Lamron
Lamron - avatar
+ 2
The issue with the code is that it is trying to access elements of the "data" list using a tuple as an index. In Python, you can't use a tuple to index a list. Instead, you should use two separate indices to access the elements of a nested list. data = [ [23, 11, 5, 14], [8, 32, 20, 5] ] total = 23 + 11 + 5 + 14 + 8 + 32 + 20 + 5 color = input() #your code goes here if color == "brown": print (int((data[0][0]+data[1][0])/total*100)) elif color == "blue": print (int((data[0][1]+data[1][1])/total*100)) elif color == "green" : print (int((data[0][2]+data[1][2])/total*100)) else : print (int((data[0][3]+data[1][3])/total*100))
30th May 2023, 9:20 AM
Naveed
Naveed - avatar
0
No actually your missing the number
29th May 2023, 7:39 AM
Kausar sar
Kausar sar - avatar
0
Hazem Hadj Ahmed So what are those couple of issues?
30th May 2023, 9:50 AM
Евгений
Евгений - avatar
0
Lothar, don't mislead the people. Lamron is right, the percentage sign *is* missing, as the sample output which the author provided does contain it. Maybe the question was edited after your post.
30th May 2023, 9:54 AM
Евгений
Евгений - avatar
0
Lothar I'm not talking about a tutorial, but about the question at the top of this discussion. It is clearly stating: ``` Output : 26% <----- SEE HERE ( of 118 persons , 23 men with brown eyes + 8 girl with brown eyes ) ```
30th May 2023, 4:10 PM
Евгений
Евгений - avatar