Sena K.

asked • 11/19/21

How to calculate score from a list of tuples in Python?

Here I want to calculate the score from a list of tuples. If the answer is Y, it will increment that specific category by 20. This is what I did but it gives the wrong score everytime. Would you guys know whats wrong with my code?

import random

q = [("Would you call yourself a thinker (Y/N):", "D"),
("Are you creative (Y/N):","D"),
("Do you like philosophy (Y/N):","D"),
("Do you like to think about complex questions (Y/N):","D"),
("Do you have an interest in artisitc pursuits like painting and writing (Y/N):","D"),
("Do you like initiating conversations (Y/N):","A"),
("Do you like to start talks with new people (Y/N):","A"),
("Is it easy for you to adjust in an enviroment where you initially do not know anyone (Y/N):","A"),
("Are you social (Y/N):","A"),
("Do you like social events (parties, fests and events) (Y/N):","A"),
("Do you mostly make your decisions by heart (Y/N):","B"),
("Do you put others before yourself (Y/N):","B"),
("Do you think that one should change their views if they hurt someone (Y/N):","B"),
("Do you often get lost in your feelings (Y/N):","B"),
("Are you run more by your feelings than logic (Y/N):","B"),
("Can you make a timetable and stick to it (Y/N):","C"),
("Do you usually follow the rules/laws (Y/N):","C"),
("Are you organised (Y/N):","C"),
("Do you plan before doing something (Y/N):","C"),
("Are you ok with following orders (Y/N):","C")]

random.shuffle(q)

answers = []
maxLength = 20
while len(answers)<maxLength:
for x in q:
user = input(x[0])
answers.append(user)

print(answers)

def calculatePercentage():
for x in q:
apercent = {}
apercent["A"] = 0
apercent["B"] = 0
apercent["C"] = 0
apercent["D"] = 0
if user == "Y":
if x[1]=="D":
apercent["D"] = apercent["D"] + 20
elif x[1]=="A":
apercent["A"] = apercent["A"] + 20
elif x[1]=="B":
apercent["B"] = apercent["B"] + 20
elif x[1]=="C":
apercent["C"] = apercent["C"] + 20
else:
apercent["A"] = 0
apercent["B"] = 0
apercent["C"] = 0
apercent["D"] = 0

print("Your extroversion percentage : ", apercent["A"], "%")
print("Your creativity percentage : ", apercent["D"], "%")
print("Your feeling percentage : ", apercent["B"], "%")
print("Your conscientious percentage : ", apercent["C"], "%")

calculatePercentage()


1 Expert Answer

By:

Boris I. answered • 11/23/21

Tutor
5 (29)

College Math and Computer Science

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.