jabela

ClassHeights

Sep 14th, 2021 (edited)
340
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.63 KB | None | 0 0
  1. """
  2. Question 3
  3.  
  4. The initial heights, as well as genders of the students In the class, must first be entered and stored using arrays.
  5.  
  6. Assuming the class has 30 students, write a program that will allow you to:
  7.  
  8. input and store the height of each student in an array called HeightArray
  9. input and store the gender of each student in an array called GenderArray
  10. calculate the average height of all students in the class
  11. calculate the average height of all males in the class
  12. calculate the average height of all females in the class
  13. """
  14.  
  15. 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]
  16. 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']
  17. TotalHeight = 0
  18. TotalCounter = 30
  19. TotalMaleHeight = 0
  20. MaleCounter = 0
  21. TotalFemaleHeight = 0
  22. FemaleCounter = 0
  23.  
  24. # HeightArray = []
  25. # GenderArray = []
  26.  
  27. # for i in range(30):
  28. #     height = int(input("Please enter height"))
  29. #     gender = str(input("Please enter gender"))
  30. #     HeightArray.append(height)
  31. #     GenderArray.append(gender)
  32.  
  33. for i in range(TotalCounter):
  34.     TotalHeight += HeightArray[i]
  35.     if GenderArray[i]=="F":
  36.         TotalFemaleHeight += HeightArray[i]
  37.         FemaleCounter += 1
  38.     else:
  39.         TotalMaleHeight += HeightArray[i]
  40.         MaleCounter += 1
  41.  
  42.  
  43. print("Average height of class",TotalHeight/TotalCounter)
  44. print("Average height of females",TotalFemaleHeight/FemaleCounter)
  45. print("Average height of males",TotalMaleHeight/MaleCounter)
Add Comment
Please, Sign In to add comment