Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """
- Question 3
- The initial heights, as well as genders of the students In the class, must first be entered and stored using arrays.
- Assuming the class has 30 students, write a program that will allow you to:
- input and store the height of each student in an array called HeightArray
- input and store the gender of each student in an array called GenderArray
- calculate the average height of all students in the class
- calculate the average height of all males in the class
- calculate the average height of all females in the class
- """
- HeightArray = [106, 120, 141, 166, 145, 137, 121, 134, 140, 102, 126, 104, 128, 161, 151, 177, 130, 148, 137, 147, 160, 111, 174, 163, 125, 141, 113, 119, 137, 133]
- GenderArray = ['F', 'M', 'M', 'F', 'F', 'F', 'M', 'M', 'F', 'F', 'M', 'F', 'M', 'M', 'M', 'F', 'M', 'F', 'F', 'M', 'M', 'F', 'F', 'M', 'F', 'M', 'F', 'F', 'M', 'M']
- TotalHeight = 0
- TotalCounter = 30
- TotalMaleHeight = 0
- MaleCounter = 0
- TotalFemaleHeight = 0
- FemaleCounter = 0
- # HeightArray = []
- # GenderArray = []
- # for i in range(30):
- # height = int(input("Please enter height"))
- # gender = str(input("Please enter gender"))
- # HeightArray.append(height)
- # GenderArray.append(gender)
- for i in range(TotalCounter):
- TotalHeight += HeightArray[i]
- if GenderArray[i]=="F":
- TotalFemaleHeight += HeightArray[i]
- FemaleCounter += 1
- else:
- TotalMaleHeight += HeightArray[i]
- MaleCounter += 1
- print("Average height of class",TotalHeight/TotalCounter)
- print("Average height of females",TotalFemaleHeight/FemaleCounter)
- print("Average height of males",TotalMaleHeight/MaleCounter)
Add Comment
Please, Sign In to add comment