Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Averages_female_male Python coded by Ken Adams
- #Average males females marks of a group of students by gender and in total.
- #Once the group size and the top mark are decided random data is generated and results
- # displayed
- import random
- group_size = 40
- group_gender = []
- group_marks = []
- top_mark =20
- for n in range(group_size):
- G=random.randint(0, 1)
- if G== 0:
- group_gender.append("F")
- else:
- group_gender.append("M")
- mark = random.randint(0, top_mark)
- group_marks.append(mark)
- print(group_gender)
- print(group_marks)
- female_count = 0
- male_count = 0
- female_total = 0
- male_total = 0
- for n in range(group_size):
- if group_gender[n] == "F":
- female_count += 1
- female_total = female_total + group_marks[n]
- else:
- male_count += 1
- male_total = male_total + group_marks[n]
- if female_count != 0:
- female_ave = female_total/female_count
- else:
- female_ave = 0
- if male_count != 0:
- male_ave = male_total/male_count
- else:
- male_ave = 0
- group_count = female_count + male_count
- group_total = female_total + male_total
- if group_count != 0:
- group_ave = group_total/group_count
- else:
- group_ave = 0;
- #female_count, female_total, female_ave, male_count, male_total, male_ave,group_count, group_total,group_ave
- print("female: count " + str(female_count) + ", total " + str(female_total)+ ", average " + str(round(female_ave,2)))
- print("male: count " + str(male_count) + ", total " + str(male_total)+ ", average " + str(round(male_ave,2)))
- print("group: count " + str(group_count) + ", total " + str(group_total)+ ", average " + str(round(group_ave,2)))
- print("bye")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement