Advertisement
Guest User

T1_new

a guest
Oct 6th, 2015
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.83 KB | None | 0 0
  1. '''
  2. http://pastebin.com/u8ntNmxd
  3.  
  4. Members DC Labels Homework DescriptionEdit Create an console application
  5. in python that keeps the evidence of students.
  6. Each student has the following information:
  7. First name
  8. Last name
  9. Courses he attends
  10. Grades for each courses
  11. A way to maintain the list of the student Features:
  12. add students
  13. add courses
  14. add grades for courses
  15. find student
  16. list students
  17. give students with mean of all courses higher then a given grade
  18. give students that are failing at at least one course
  19. All these have to implemented using lists and dictionaries.
  20. There will be a pretty menu from where you can do all of this (for reading from the console, see raw_input() function).
  21. For any other questions, this should answer just about everything about the language.
  22. List documentation Dictionary documentation From those links you can also find sets and tuples.
  23. V1: http://pastebin.com/u8ntNmxd
  24.  
  25. '''
  26.  
  27.  
  28. students = {}
  29.  
  30. def add_student(first_name, last_name, cnp):
  31. if students.get(cnp) is None:
  32. students[cnp] = {
  33. 'first_name': first_name,
  34. 'last_name': last_name,
  35. 'courses': {}
  36. }
  37. return True
  38. else:
  39. return False
  40.  
  41. def add_course(cnp, course):
  42. if students[cnp]['courses'].get(course) is None:
  43. students[cnp]['courses'][course] = []
  44. return True
  45. else:
  46. return False
  47.  
  48.  
  49. def add_grade(cnp, course, grade):
  50. if students[cnp]['courses'].get(course) is None:
  51. return False
  52. else:
  53. students[cnp]['courses'][course].append(grade)
  54. return True
  55.  
  56. def find_student_by_cnp(cnp):
  57. if students.get(cnp) is None:
  58. return False
  59. else:
  60. print 'First name: ', students[cnp]['first_name']
  61. print 'Last name: ', students[cnp]['last_name']
  62. print 'Courses: ', students[cnp]['courses']
  63. print 10*'-'
  64. return True
  65.  
  66. def find_student_by_fname(fname):
  67. '''if not students:
  68. return False
  69. else:'''
  70. for student, atributes in students.items():
  71. if atributes['first_name'] == fname:
  72. print students[student]
  73.  
  74.  
  75. def list_students():
  76. if not students:
  77. return False
  78. else:
  79. print 10*'-'
  80. for student in students.values():
  81. print student['first_name'], student['last_name']
  82. return True
  83.  
  84. def del_student_by_cnp(student_cnp):
  85. if students.get(student_cnp) is None:
  86. return False
  87. else:
  88. del students[student_cnp]
  89. return True
  90.  
  91. def del_student_by_fname(fname):
  92. if not students:
  93. return False
  94. else:
  95. for student, atributes in students.items():
  96. if atributes['first_name'] == fname:
  97. del students[student]
  98. return True
  99.  
  100. def del_student_by_lname(lname):
  101. if not students:
  102. return False
  103. else:
  104. for student, atributes in students.items():
  105. if atributes['last_name'] == lname:
  106. del students[student]
  107. def grade_mean(student_cnp):
  108. if students.get(student_cnp) is None:
  109. return False
  110. else:
  111. media = sum(
  112. for curs, note in students[student_cnp]['courses'].items()
  113.  
  114. print 'Suma notelor pentru', students[student_cnp]['first_name'], 'este', sumation
  115.  
  116. '''def students_with_grade_higher_than(grade)
  117. if not students:
  118. return False
  119. else:
  120. for student, atributes in students.items():
  121. if atributes[ '''
  122.  
  123. def run():
  124. add_student('Andrei', 'Nasosu', 1)
  125. add_student('Andrei', 'Slabu', 5)
  126. add_student('Florin', 'Strunga', 2)
  127. add_student('Dumitru', 'Candale', 3)
  128. add_student('Ionut', 'Popescu', 4)
  129.  
  130. find_student_by_fname('bla')
  131.  
  132.  
  133. add_course(1, 'Mate')
  134. add_course(1, 'Romana')
  135. add_course(2, 'Geogra')
  136. add_course(3, 'Bio')
  137.  
  138. add_grade(1, 'Mate', 8)
  139. add_grade(1, 'Romana', 10)
  140. add_grade(2, 'Geogra', 7)
  141. add_grade(3, 'Bio', 6)
  142.  
  143. find_student_by_cnp(1)
  144. find_student_by_cnp(2)
  145. find_student_by_cnp(3)
  146.  
  147. list_students()
  148.  
  149. del_student_by_fname('Andrei')
  150.  
  151. list_students()
  152.  
  153. del_student_by_cnp(2)
  154.  
  155. list_students()
  156.  
  157. del_student_by_lname('Candale')
  158.  
  159. list_students()
  160.  
  161. grade_mean(1)
  162.  
  163. run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement