ArtofShadows.com see more from the shoots! NSFW

Python – SoloLearn Python Data Structures, Apple Of My Eye

I finished the ‘Python Intermediate’ course and immediately started up ‘Python Data Structures’, got to this fun problem in the ‘List’ section. Data structures are typically my strength., but I may not yet be super efficient. They work though.

Basically we are making a program to accept a user input of one of four eye colors, males and females in this group, then we will output the percentage of that eye color in the group.

This one was a lil tricky, but this below was my working solution, I have not looked yet but I believe you can do this better with a for loop. So I created a ‘colors’ list in proper order to get the index needed like if the input was ‘blue’ then that index is ‘1’. Then with color index found now add the sum(data[0][1]) + sum(data[1][1]) to get the male + females total color count for blue, then just do the percentage math.

data = [
  #males
  [23, 11, 5, 14],
  #females
  [8, 32, 20, 5]
]
color = input()

#your code goes here

total = sum(data[0]) + sum(data[1])
colors = ['brown', 'blue', 'green', 'black']
color_total = data[0][colors.index(color)] + data[1][colors.index(color)]

print(int((color_total / total) * 100))

Leave a Comment