simbax

studenci.py

Dec 28th, 2012
6,447
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.77 KB | None | 0 0
  1. # coding=utf-8
  2. # Lista Ocen Studentów
  3. class Student:
  4.     imie = ""
  5.     nazwisko = ""
  6.     ocena = 0.0
  7.  
  8. studenci = []
  9. nr = 0
  10. while True:
  11.     naz = raw_input("Podaj nazwisko studenta nr %i (ENTER = koniec): " % (nr + 1))
  12.     if not naz: break
  13.     studenci.append(Student())
  14.     studenci[nr].nazwisko = naz
  15.     studenci[nr].imie = raw_input("Podaj imię studenta nr %i: " % (nr + 1))
  16.     studenci[nr].ocena = float(raw_input("Podaj ocenę studenta nr %i: " % (nr + 1)))
  17.     nr += 1
  18.  
  19. print
  20. print "%-4s %-14s %-10s %7s" % ("L.p.", "Nazwisko", "Imię", "Ocena")
  21. for s in studenci:
  22.     print "%3i. %-14s %-10s %7.1f" % (studenci.index(s)+1, s.nazwisko, s.imie, s.ocena)
  23. srednia = 0
  24. for s in studenci:
  25.     srednia += s.ocena
  26. srednia = srednia/len(studenci)
  27. print "%13s %25.2f" % ("Średnia ocen:", srednia)
Advertisement
Add Comment
Please, Sign In to add comment