In: Computer Science
Create a python application that inputs, processes and stores student data.
Specifications: 1. Your application should be able to accept Student data from the user and add the information in a file type of your choice.
2. your application is a menu driven and allow the user to choose from the following menu
Menu: 1 – Add students to file
2 – print all the student information
3 – print specific student information using studentID
4 – Exit the program
2. Student Data should include the following • StudentID • FirstName • LastName • Major • Phone • GPA • Date of Birth
Example: C777777 James Bond CSAT 416-222-2222 3.88 October 15th, 1970
3. Your application should provide the functionality to display the student data as needed using student number key
4. Your application should calculate the average gpa of all the students and show the total gpa of the class along with the displayed student in previous step.
CODE:
#function to print the menu
def printMenu():
print('\n1. Add students to file')
print('2. Print all students information')
print('3. Print student information using studentId')
print('4. Exit program')
#function to add a student to the passed student dictionary
def addStudents(studentDict):
#asking the user of the inputs
iD = input('Enter the student id: ')
tempDict =
{'fName':'','lName':'','major':'','phone':'','gpa':0.0,'dob':''}
tempDict['fName'] = input('Enter the first name of the student:
')
tempDict['lName'] = input('Enter the last name of the student:
')
tempDict['major'] = input('Enter the major: ')
tempDict['phone'] = input('Enter the phone number: ')
tempDict['gpa'] = float(input('Enter the gpa: '))
tempDict['dob'] = input('Enter the date of birth: ')
#adding the student to the dictionary
studentDict[iD] = tempDict
#returning the dictionary
return studentDict
#function to print the studentInfo
def printStudentInfo(studentDict,iD):
#forms an outString
outString = ""
outString += 'ID: '+iD+" "
outString += 'Name: '+studentDict['fName']+"
"+studentDict['lName']+" "
outString += 'Major: '+studentDict['major']+" "
outString += 'Phone Number: '+studentDict['phone']+" "
outString += 'GPA: '+str(studentDict['gpa'])+" "
outString += 'Date of Birth: '+studentDict['dob']+" "
#returns a string with the formatted Data
return outString
#prints all the student in the passed dictionary
def printStudents(studentDict):
for i in studentDict.keys():
print("Id: "+i+" "+printStudentInfo(studentDict[i],i))
#asks the user to enter an Id
def printStudentSpecific(studentDict):
iD = input('Enter the id of the student: ')
#if the id is present in the list
if(iD in studentDict.keys()):
#the details are displayed
print(printStudentInfo(studentDict[iD],iD))
else:
print('Student with Id: {} not found!'.format(iD))
#function to calculate the sum and average of the gpa of the
class
def displayAverageGpa(studentDict):
summation = 0
#calculating the sum
for i in studentDict.keys():
summation += studentDict[i]['gpa']
#displaying the average
print('Average GPA of students:
{}'.format(str(round(summation/len(studentDict.keys()),2))))
print('Total GPA of students:
{}'.format(str(round(summation,2))))
#main method
def main():
#a dictionary to store the information of all students in a
class
studentDict = {}
#opening an output File
file = open('studentsInfo.txt','w')
while(True):
#asking the user to make a choice
printMenu()
choice = int(input('Enter a choice: '))
#according to the choice functions are called
if(choice == 1):
studentDict = addStudents(studentDict)
elif(choice == 2):
printStudents(studentDict)
elif(choice == 3):
printStudentSpecific(studentDict)
elif(choice == 4):
displayAverageGpa(studentDict)
#writing the student details in the file before exiting the
code
for i in studentDict.keys():
file.writelines(printStudentInfo(studentDict[i],i)+"\n")
file.close()
print('Bye!')
break
else:
print('Invalid Option!')
#calling the main function
main()
___________________________________________
CODE IMAGES AND OUTPUT:
_________________________________________
OUTPUT:
_____________________________________________________
Feel free to ask any questions in the comments section
Thank You!