Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Python only. Create a database of following details for at least 50 students and

ID: 3757001 • Letter: P

Question

Python only.

Create a database of following details for at least 50 students and store it in a text file.

Student ID

first name

last name

phone number (xxx-xxx-xxxx)

email id

Major

Create another database of following details for those students and store it in another text file.

Student ID

Courses taken for each semester and Scores for each course which includes overall average of assignments, quizzes, projects and exams.

For example:

Student _ID Campus year semester course_number average_assignment average_quizzes average_projects average_exams……………………………………………..    

Example:

2451813 2015 spring CS123 90 91 98 92 CS120 80 70 75 2 fall Math250 92 84 88 91

2016 spring CS121 90 91 98 92 CS125 80 70 75 2 fall Math252 92 84 88 91

Note: You can change/manipulate the order of data entries as needed.

Exercise:1

Choose an appropriate data type and data structure (lists, lists of list, dictionary etc.) for storing the information in your program.

Exercise:2

Write a function which takes student ID as input and displays all information of the student stored in file-1 and file-2.

Exercise:3

Write a function which takes student ID and specify course number as inputs and displays the score information of that course.

Exercise:4

Write a function which takes student ID and specify semester name as inputs and displays the grade for all the courses taken in that semester.

Exercise:5

Write a function which takes student ID as input and displays the course number of maximum grade and minimum grade with the associated grade.

Exercise:6

Show an example of using split and join method.

Exercise:7

Show an example of adding data entry for a new student, modifying a student’s score for a specific semester and deleting a student entry.

Exercise:8

Write a function which takes a parameter and sorts the entire list of students and displays all the details of all students. For example, if you specify the student ID or first name, the entries should be sorted accordingly.

Exercise:9

Write a function which takes student id as parameter and finds whether the student is a freshmen or sophomore or junior or senior.

Exercise:10

Programmatically create a file storing all the student’s information including the added/modified entry.

Explanation / Answer

print 'Welcome to student database management program coded by Choyon'
# Must have student_db.txt as database resource
# demo database file is mentioned in folder
# Then run the code to let it work fine
while True:
    try:
        file_temp = open('student_db.txt', 'r')
    except IOError:
        print 'To run this program, you must have student_db.txt file in the same folder ... '
               'This program is coded and developed by Choyon Ahmed'
        exit_prompt = input('Press enter/CTRL+C to close the window ... ==> ')
    fetched_file = eval(file_temp.read())
    try:
        print 'Total Entries in database:', len(fetched_file.keys())
        command1 = raw_input('What you want me to do(type the number. ex. 1)? '
                             '1. Update Student Database '
                             '2. View Full Student Database '
                             '3. Find a Student by Roll Number ==> ')
        if command1 == '1':
            command2 = raw_input('1. Add Student Data '
                                 '2. Delete Student Data '
                                 '3. Clear Full Database ==> ')
            if command2 == '1':
                file_temp.close()
                file_edit_temp = open('student_db.txt', 'r')
                file_edit = eval(file_edit_temp.read())
                file_edit_temp.close()
                key1 = raw_input('Enter New Student Roll Number: ==> ')
                print 'Enter Student data as asked :'
                student_name = ' Student Name: %r ' % raw_input('Student Name: ==> ')
                cgpa = ' CGPA: %r ' % float(raw_input('CGPA: ==> '))
                credit_complete = ' Total Credit Completed: %r ' % int(raw_input('Total Credit Completed: ==> '))
                join_date = ' Date of Registration: %r ' % raw_input('Date of Registration: ==> ')
                expiration_date = ' Session ends: %r ' % raw_input('Session ends: ==> ')
                create_value = student_name + cgpa + credit_complete + join_date + expiration_date
                file_edit[key1] = create_value
                file_edit_temp = open('student_db.txt', 'w')
                file_edit_temp.write('%r' % file_edit)
                file_edit_temp.close()
                print 'SYSTEM: Data Updated Successfully for student roll', key1
                # This portion is under development.
                continue
            elif command2 == '2':
                file_temp1 = open('student_db.txt', 'r')
                file_temp2 = eval(file_temp1.read())
                file_temp1.close()
                key_to_delete = raw_input('Enter Student Roll number to delete: ==> ')
                try:
                    del file_temp2[key_to_delete]
                    file_temp1 = open('student_db.txt', 'w')
                    file_temp1.write('%r' % file_temp2)
                    file_temp1.close()
                    print 'Roll number', key_to_delete, 'Has been deleted successfully!'
                    continue
                except KeyError:
                    print 'ERROR: Student Roll Number is not assigned to the database!'
                    continue
            elif command2 == '3':
                print 'Are you sure want to clear the whole database?If you proceed, this action cannot be reverted '
                      'back!'
                delete_confirm = raw_input('Type Y to continue or N to abort the action ==> ')
                if delete_confirm == 'Y':
                    file_temp.close()
                    file_temp = open('student_db.txt', 'w')
                    file_temp.write('{}')
                    file_temp.close()
                    print 'SYSTEM: Database cleared successfully!'
                    continue
                elif delete_confirm == 'N':
                    print 'SYSTEM: Action Aborted ...'
                    continue
                else:
                    print 'SYSTEM: Invalid Command!'
                    continue
            else:
                print 'ERROR: Invalid Command!'
                continue
        elif command1 == '2':
            checkme = len(fetched_file.keys())
            if checkme == 0:
                print 'SYSTEM: There is no student information stored in the database!'
                continue
            else:
                for key in fetched_file:
                    print 'Roll Number:', key
                    print fetched_file[key]
                continue
        elif command1 == '3':
            while True:
                find_student = raw_input('Type student roll number : ==> ')
                try:
                    print 'Student Information: ', fetched_file[find_student]
                    print ' Roll number: %r' % find_student
                    # might be extended with something more here later
                except KeyError:
                    print 'ERROR: Roll number not found in the database'
                    continue
        else:
            print 'ERROR: Invalid Command!'
            continue
    except ValueError:
        print 'ERROR: Invalid Command!'
        continue