Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2018
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.12 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. '''
  3. class Student:
  4. uczelnia = "AM Gdynia"
  5. wydzial = "Wydział Nawigacyjny"
  6. kierunek = "TM"
  7.  
  8. def __init__(self, imie, nazwisko, srednia):
  9. self.imie = imie
  10. self.nazwisko = nazwisko
  11. self.srednia = srednia
  12.  
  13. def opisz_studenta(self):
  14. print(self.uczelnia, self.wydzial, self.kierunek, self.imie, self.nazwisko)
  15. if self.srednia > 4.2:
  16. print("Dobry student\n")
  17. elif self.srednia <= 4.2 and self.srednia > 3.3:
  18. print("Przeciętny student\n")
  19. else:
  20. print("Słaby student")
  21.  
  22.  
  23. student1 = Student("Jan", "Kowalski", 4.5)
  24. student2 = Student("Anna", "Zawadzka", 4.1)
  25. student3 = Student("Adam", "Nowak", 3.0)
  26. student1.opisz_studenta()
  27. student2.opisz_studenta()
  28. student3.opisz_studenta()
  29. '''
  30. class Student:
  31. def __init__(self, nazwisko, średnia, wiek,):
  32. self.nazwisko = nazwisko
  33. self.średnia = średnia
  34. self.wiek = wiek
  35. return
  36.  
  37. class ListaStud:
  38. def __init__(self):
  39. self.listaStudentów = []
  40.  
  41. def dodajDoListy(self, nazwisko, średnia, wiek):
  42. self.listaStudentów.append(Student(nazwisko, średnia, wiek))
  43. return
  44.  
  45. def podajLiczbęStudentów(self):
  46. return len(self.listaStudentów)
  47.  
  48. #Inne metody klasy ListaStud
  49.  
  50. def drukujPosortowanąListę(self):
  51. print("\n posortowana \n")
  52. listaPosortowana = sorted(self.listaStudentów, key = lambda student: student.nazwisko)
  53. for student in listaPosortowana:
  54. print(student.nazwisko, student.średnia, student.wiek)
  55. return
  56.  
  57. def drukujListęStudentów(self):
  58. for student in self.listaStudentów:
  59. print(student.nazwisko, student.średnia, student.wiek)
  60. return
  61.  
  62. def sredniasredniej(self):
  63. self.sredniasr = 0
  64. self.licznik = 0
  65. for student in self.listaStudentów:
  66. self.sredniasr += student.średnia
  67. self.licznik += 1
  68. self.wynik = self.sredniasr / self.licznik
  69. print(self.wynik)
  70. return
  71.  
  72. def stypendium(self, progi):
  73. print("\n- Lista stypendystów -")
  74. self.l_stypend = []
  75. for stud in self.listaStudentów:
  76. if stud.srednia >= progi:
  77. self.l_stypend.append(stud)
  78. for student in self.l_stypend:
  79. print(student.nazwisko, student.wynik, student.wiek)
  80. return
  81.  
  82.  
  83.  
  84. #tworzenie okiektu i wywołanie metod:
  85. obiekt=ListaStud()
  86. obiekt.dodajDoListy('Kowalski', 3.73, 19)
  87. obiekt.dodajDoListy('Wiśniewski', 4.1, 21)
  88. obiekt.dodajDoListy('Staśkiewicz', 3.02, 23)
  89.  
  90. print('\n Ilość studentów na liście: ',obiekt.podajLiczbęStudentów())
  91. obiekt.drukujListęStudentów()
  92. obiekt.dodajDoListy('Kowalewski', 3.73, 19)
  93. obiekt.dodajDoListy('Wiśniewiecki', 4.55, 21)
  94. obiekt.dodajDoListy('Staszkiwicz', 4.02, 24)
  95.  
  96. print('\n Ilość studentów na rozszerzonej liście: ', obiekt.podajLiczbęStudentów())
  97. obiekt.drukujListęStudentów()
  98. obiekt.drukujPosortowanąListę()
  99.  
  100.  
  101. obiekt.sredniasredniej()
  102.  
  103. obiekt.stypendium(obiekt.sredniasredniej())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement