Advertisement
biswasrohit20

da

Apr 21st, 2021
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.55 KB | None | 0 0
  1. def getData():
  2. possible_answers = [ "strongly agree", "agree", "neutral", "disagree", "strongly disagree"]
  3. answer = input("Please enter your response ")
  4. all_answers = []
  5. while answer != "":
  6. if answer.lower() in possible_answers:
  7. all_answers.append(answer.lower())
  8. answer = input("Please enter your response ")
  9.  
  10. return all_answers
  11.  
  12.  
  13. def countAnswers(data):
  14. a = 0
  15. sa = 0
  16. n = 0
  17. d = 0
  18. sd = 0
  19.  
  20. for answer in data:
  21. if answer == "strongly agree":
  22. sa += 1
  23. elif answer == "agree":
  24. a += 1
  25. elif answer == "neutral":
  26. n += 1
  27. elif answer == "disagree":
  28. d += 1
  29. elif answer == "strongly disagree":
  30. sd += 1
  31.  
  32. answer_count = [sd, a, n, d, sd]
  33. return answer_count
  34.  
  35.  
  36. def main():
  37. response_count = countAnswers(getData())
  38. percentages = []
  39. if sum(response_count) == 0:
  40. percentages = [0, 0, 0, 0, 0]
  41. else:
  42. for i in response_count:
  43. percentages.append((i/sum(response_count))*100)
  44.  
  45. print("Survey Results")
  46. print("-"*25)
  47. print('{0:20} {1}%'.format("Strongly Agree", "{:.2f}".format(percentages[0])))
  48. print('{0:20} {1}%'.format("Agree", "{:.2f}".format(percentages[1])))
  49. print('{0:20} {1}%'.format("Neutral", "{:.2f}".format(percentages[2])))
  50. print('{0:20} {1}%'.format("Disagree", "{:.2f}".format(percentages[3])))
  51. print('{0:20} {1}%'.format("Strongly Disagree", "{:.2f}".format(percentages[4])))
  52.  
  53.  
  54. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement