Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- '''
- http://pastebin.com/u8ntNmxd
- Members DC Labels Homework DescriptionEdit Create an console application
- in python that keeps the evidence of students.
- Each student has the following information:
- First name
- Last name
- Courses he attends
- Grades for each courses
- A way to maintain the list of the student Features:
- add students
- add courses
- add grades for courses
- find student
- list students
- give students with mean of all courses higher then a given grade
- give students that are failing at at least one course
- All these have to implemented using lists and dictionaries.
- There will be a pretty menu from where you can do all of this (for reading from the console, see raw_input() function).
- For any other questions, this should answer just about everything about the language.
- List documentation Dictionary documentation From those links you can also find sets and tuples.
- V1: http://pastebin.com/u8ntNmxd
- '''
- students = {}
- def add_student(first_name, last_name, cnp):
- if students.get(cnp) is None:
- students[cnp] = {
- 'first_name': first_name,
- 'last_name': last_name,
- 'courses': {}
- }
- return True
- else:
- return False
- def add_course(cnp, course):
- if students[cnp]['courses'].get(course) is None:
- students[cnp]['courses'][course] = []
- return True
- else:
- return False
- def add_grade(cnp, course, grade):
- if students[cnp]['courses'].get(course) is None:
- return False
- else:
- students[cnp]['courses'][course].append(grade)
- return True
- def find_student_by_cnp(cnp):
- if students.get(cnp) is None:
- return False
- else:
- print 'First name: ', students[cnp]['first_name']
- print 'Last name: ', students[cnp]['last_name']
- print 'Courses: ', students[cnp]['courses']
- print 10*'-'
- return True
- def find_student_by_fname(fname):
- '''if not students:
- return False
- else:'''
- for student, atributes in students.items():
- if atributes['first_name'] == fname:
- print students[student]
- def list_students():
- if not students:
- return False
- else:
- print 10*'-'
- for student in students.values():
- print student['first_name'], student['last_name']
- return True
- def del_student_by_cnp(student_cnp):
- if students.get(student_cnp) is None:
- return False
- else:
- del students[student_cnp]
- return True
- def del_student_by_fname(fname):
- if not students:
- return False
- else:
- for student, atributes in students.items():
- if atributes['first_name'] == fname:
- del students[student]
- return True
- def del_student_by_lname(lname):
- if not students:
- return False
- else:
- for student, atributes in students.items():
- if atributes['last_name'] == lname:
- del students[student]
- def grade_mean(student_cnp):
- if students.get(student_cnp) is None:
- return False
- else:
- media = sum(
- for curs, note in students[student_cnp]['courses'].items()
- print 'Suma notelor pentru', students[student_cnp]['first_name'], 'este', sumation
- '''def students_with_grade_higher_than(grade)
- if not students:
- return False
- else:
- for student, atributes in students.items():
- if atributes[ '''
- def run():
- add_student('Andrei', 'Nasosu', 1)
- add_student('Andrei', 'Slabu', 5)
- add_student('Florin', 'Strunga', 2)
- add_student('Dumitru', 'Candale', 3)
- add_student('Ionut', 'Popescu', 4)
- find_student_by_fname('bla')
- add_course(1, 'Mate')
- add_course(1, 'Romana')
- add_course(2, 'Geogra')
- add_course(3, 'Bio')
- add_grade(1, 'Mate', 8)
- add_grade(1, 'Romana', 10)
- add_grade(2, 'Geogra', 7)
- add_grade(3, 'Bio', 6)
- find_student_by_cnp(1)
- find_student_by_cnp(2)
- find_student_by_cnp(3)
- list_students()
- del_student_by_fname('Andrei')
- list_students()
- del_student_by_cnp(2)
- list_students()
- del_student_by_lname('Candale')
- list_students()
- grade_mean(1)
- run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement