You are on page 1of 4

General Requirements:

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

m
3 – print specific student information using studentID

er as
4 – Exit the program

co
eH w
2. Student Data should include the following

o.
 StudentID rs e
ou urc
 FirstName
 LastName
 Major
o

 Phone
aC s

 GPA
vi y re

 Date of Birth

Example:
ed d

C777777
ar stu

James
Bond
CSAT
416-222-2222
is

3.88
Th

October 15th, 1970

3. Your application should provide the functionality to display the student data as needed using
student number key
sh

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.

This study source was downloaded by 100000829143749 from CourseHero.com on 07-11-2021 01:39:21 GMT -05:00

https://www.coursehero.com/file/74578282/Assignment-2doc/
4. Submit your source code along this file on Moodle. Projects with no source code will rewarded
zero.
def main():
while True:
print("1- Add Students to a file")
print("2 print all the student information")
print("3 print specific student information using studentID")
print("4 Exit the program")
user_choice = int(input("Enter your choice"))
if user_choice == 1:
id = input("Enter StudentId")
first = input("Enter your first_name")
last= input("Enter your last_name")
major = input("Enter Major")
number = input("Enter phone number")
score = input("Enter GPA")
dob = input("Enter date of birth")

file_name_open = open("file_student", "a")


file_name_open.write("\n")

m
file_name_open.write(id)

er as
file_name_open.write("\n")

co
eH w
file_name_open.write(first)
file_name_open.write("\n")

o.
rs e
file_name_open.write(last)
file_name_open.write("\n")
ou urc
file_name_open.write(major)
file_name_open.write("\n")
o

file_name_open.write(number)
aC s

file_name_open.write("\n")
vi y re

file_name_open.write(score)
file_name_open.write("\n")
ed d

file_name_open.write(dob)
ar stu

elif user_choice == 2:
file_name_open = open("file_student", "r")
print(file_name_open.read())
elif user_choice == 3:
is

id = input("Enter id")
id = id
Th

file = open("file_student", "r")


data = file.readlines()
data = [x.replace('\n', '') for x in data]
print(type(data))
sh

print(data)
index_position = data.index(id)

for i in range(index_position, index_position + 7):


print(data[i])

num_lines = sum(1 for line in open("file_student", "r"))


no_of_students = num_lines / 6

This study source was downloaded by 100000829143749 from CourseHero.com on 07-11-2021 01:39:21 GMT -05:00

https://www.coursehero.com/file/74578282/Assignment-2doc/
f = open("file_student", "r")

lines = f.readlines()
GPA = 0
for i in range(5, num_lines, 7):
GPA += float(lines[i])

print(f"Average GPA IS {GPA / (no_of_students)}")

elif user_choice == 4:
break

main()

AND

import csv

student_fields = ['StudentID', 'FirstName', 'LastName', 'Major', 'Phone', 'GPA',

m
'DOB']

er as
studentDb = 'students.csv'

co
eH w
def display_menu():

o.
print("1. add students to file")

rs e
print("2. print all the student information")
ou urc
print("3. print specific student information using studentID")
print("4. Exit the program")
o

def add_student():
print("--- add student to file ---")
aC s
vi y re

student_data = []
for field in student_fields:
value = input("Enter " + field + ": ")
student_data.append(value)
ed d

with open(studentDb, "a") as f:


ar stu

writer = csv.writer(f)
writer.writerows([student_data])

print("Student data saved")


is
Th

def view_students():
print("--- print all the student information ---")
with open(studentDb, "r") as f:
sh

reader = csv.reader(f)
for x in student_fields:
print(x, end='\t |')
print("\n")

for row in reader:


for item in row:
print(item, end='\t |')

This study source was downloaded by 100000829143749 from CourseHero.com on 07-11-2021 01:39:21 GMT -05:00

https://www.coursehero.com/file/74578282/Assignment-2doc/
print("\n")

def calculate_gpa():
with open(studentDb, "r") as f:
reader = csv.reader(f)
gpa = 0
counter = 0
for row in reader:
counter = counter + 1
gpa = gpa + float(row[5])
return gpa / counter

def search_student():
roll = input("--- print specific student information using studentID --- ")
avg_gpa = calculate_gpa()
with open(studentDb, "r") as f:
reader = csv.reader(f)
for row in reader:
if len(row) > 0:

m
er as
if roll == row[0]:
print("---Student Found ---")

co
print("Student ID: ", row[0])

eH w
print("First Name: ", row[1])
print("Last Name: ", row[2])

o.
print("Major: ", row[3])
rs e
print("Phone: ", row[4])
ou urc
print("GPA: ", row[5])
print("DOB: ", row[6])
print("Avg GPA:", "{:.2f}".format(avg_gpa))
break
o

else:
aC s

print("Student ID not found ")


vi y re

input("Press any key to continue")

while True:
display_menu()
ed d
ar stu

choice = input("Enter your choice: ")


if choice == '1':
add_student()
elif choice == '2':
is

view_students()
elif choice == '3':
Th

search_student()
else:
break

print("exit the program")


sh

This study source was downloaded by 100000829143749 from CourseHero.com on 07-11-2021 01:39:21 GMT -05:00

https://www.coursehero.com/file/74578282/Assignment-2doc/
Powered by TCPDF (www.tcpdf.org)

You might also like