Apple Of My Eye task. Searching for easier way
Hello Guys I was able to solve the task in list operators from Python Data Structure, but my solution looks very complicated. Maybe you can help me to find an easier way to solve it Task: List Operations 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 data = [ [23, 11, 5, 14], [8, 32, 20, 5] ] PY 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 Explanation: There are 11+32=43 people with blue eyes, which is 36% of the total. My Solution: data = [ [23, 11, 5, 14], [8, 32, 20, 5] ] #Sum of People in Room People = int(sum(data[0]+data[1])) # print(int(People)) color = input() #working with if operator and using the formular to count the percentage if color == 'brown': print(int( int(data[0][0]+data[1][0])/People*100 )) elif color == 'blue': print(int( int(data[0][1]+data[1][1])/People*100 )) elif color == 'green': print(int( int(data[0][2]+data[1][2])/People*100 )) elif color == 'black': print(int( int(data[0][3]+data[1][3])/People*100 ))