+ 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))
11 Antworten
+ 7
Lamron ,
the percentage sign is *not* required here. the sample output is without it.
+ 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 ...
+ 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.
+ 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))
+ 2
You didn't add the percentage sign as shown in the sample output.
+ 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))
0
No actually your missing the number
0
Hazem Hadj Ahmed So what are those couple of issues?
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 )
```