Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def getData():
- possible_answers = [ "strongly agree", "agree", "neutral", "disagree", "strongly disagree"]
- answer = input("Please enter your response ")
- all_answers = []
- while answer != "":
- if answer.lower() in possible_answers:
- all_answers.append(answer.lower())
- answer = input("Please enter your response ")
- return all_answers
- def countAnswers(data):
- a = 0
- sa = 0
- n = 0
- d = 0
- sd = 0
- for answer in data:
- if answer == "strongly agree":
- sa += 1
- elif answer == "agree":
- a += 1
- elif answer == "neutral":
- n += 1
- elif answer == "disagree":
- d += 1
- elif answer == "strongly disagree":
- sd += 1
- answer_count = [sd, a, n, d, sd]
- return answer_count
- def main():
- response_count = countAnswers(getData())
- percentages = []
- if sum(response_count) == 0:
- percentages = [0, 0, 0, 0, 0]
- else:
- for i in response_count:
- percentages.append((i/sum(response_count))*100)
- print("Survey Results")
- print("-"*25)
- print('{0:20} {1}%'.format("Strongly Agree", "{:.2f}".format(percentages[0])))
- print('{0:20} {1}%'.format("Agree", "{:.2f}".format(percentages[1])))
- print('{0:20} {1}%'.format("Neutral", "{:.2f}".format(percentages[2])))
- print('{0:20} {1}%'.format("Disagree", "{:.2f}".format(percentages[3])))
- print('{0:20} {1}%'.format("Strongly Disagree", "{:.2f}".format(percentages[4])))
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement