Advertisement
kenadams53

Averages_female_male

Aug 27th, 2019
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 KB | None | 0 0
  1. #Averages_female_male Python coded by Ken Adams
  2. #Average males females marks of a group of students by gender and in total.
  3. #Once the group size and the top mark are decided random data is generated and results
  4. # displayed
  5. import random
  6. group_size = 40
  7. group_gender = []
  8. group_marks = []
  9. top_mark =20
  10. for n in range(group_size):
  11. G=random.randint(0, 1)
  12. if G== 0:
  13. group_gender.append("F")
  14. else:
  15. group_gender.append("M")
  16. mark = random.randint(0, top_mark)
  17. group_marks.append(mark)
  18.  
  19. print(group_gender)
  20. print(group_marks)
  21.  
  22. female_count = 0
  23. male_count = 0
  24. female_total = 0
  25. male_total = 0
  26.  
  27. for n in range(group_size):
  28. if group_gender[n] == "F":
  29. female_count += 1
  30. female_total = female_total + group_marks[n]
  31. else:
  32. male_count += 1
  33. male_total = male_total + group_marks[n]
  34. if female_count != 0:
  35. female_ave = female_total/female_count
  36. else:
  37. female_ave = 0
  38.  
  39. if male_count != 0:
  40. male_ave = male_total/male_count
  41. else:
  42. male_ave = 0
  43. group_count = female_count + male_count
  44. group_total = female_total + male_total
  45. if group_count != 0:
  46. group_ave = group_total/group_count
  47. else:
  48. group_ave = 0;
  49.  
  50. #female_count, female_total, female_ave, male_count, male_total, male_ave,group_count, group_total,group_ave
  51. print("female: count " + str(female_count) + ", total " + str(female_total)+ ", average " + str(round(female_ave,2)))
  52. print("male: count " + str(male_count) + ", total " + str(male_total)+ ", average " + str(round(male_ave,2)))
  53. print("group: count " + str(group_count) + ", total " + str(group_total)+ ", average " + str(round(group_ave,2)))
  54. print("bye")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement