# This is Student management system project
print("\n===Welcome to Student Management System App===")
# Storage for student information
students = []
# Used as a list index to add GPA of student. also, counts amount of students added.
student_index = 0
# Credit point of subjects as: mathematics, english, physics, emerging technology, inclusiveness, civic and moral education.
credit_point_of_subjects = [4, 3, 3, 3, 2, 2]
# Total credit hour
credit_total = 17
# Grade calculator
def student_grade(marks, credit_total, credit_hour_of_subjects):
"""This function calculates grades of the students"""
# grade to be divided will be the total sum of: (credit hour of subject * number_grade that student get)
grade_tobe_divided = 0
# Stores number grade of all subjects after looping
all_subjects_number_grade = []
# Look for all subjects mark and give number_grade and letter_grade for it
for mark in marks:
if mark >= 90:
letter_grade = "A+"
number_grade = 4
elif mark >= 85:
letter_grade = "A"
number_grade = 4
elif mark >= 80:
letter_grade = "A-"
number_grade = 3.75
elif mark >= 75:
letter_grade = "B+"
number_grade = 3.5
elif mark >= 70:
letter_grade = "B"
number_grade = 3
elif mark >= 65:
letter_grade = "B-"
number_grade = 2.75
elif mark >= 60:
letter_grade = "C+"
number_grade = 2.5
elif mark >= 50:
letter_grade = "C-"
number_grade = 2
else:
letter_grade = "F"
number_grade = 0
# adds number grade to the above all_subjects_number_grade list
all_subjects_number_grade.append(number_grade)
# multiplies credit hour with number grade of the subjects
for i in range(len(all_subjects_number_grade)):
# grade * credit
grade_quality = all_subjects_number_grade[i] * credit_hour_of_subjects[i]
# Add multiplied number_grade and credit hour to grade_tobe_divided
grade_tobe_divided +=grade_quality
# Finding and adding GPA into the dictionary
GPA = round(grade_tobe_divided / credit_total, 2)
return GPA
# storing students
def add_students(fname, lname, id, mathematics, english, physics, em_tech, inclusiveness, cme, hpe):
"""A function to store name, id, score of students into students dictionary"""
# I check for length because I will add items to the last index
i = len(students)
students.append({})
students[i]["firstname"] = fname
students[i]["lastname"] = lname
students[i]["ID"] = id
students[i]["mathematics"] = mathematics
students[i]["english"] = english
students[i]["physics"] = physics
students[i]["em_tech"] = em_tech
students[i]["inclusiveness"] = inclusiveness
students[i]["civic"] = cme
students[i]["hpe"] = hpe
# Printig list of students
def list_of_students():
"""Loop through students and print list of all students"""
print("Firstname | Lastname | ID | Maths | Eng | Phys | EmTech | Incl | CME | HPE | GPA |")
for student in students:
for value in student.values():
print(value, end = " | ")
print()
print()
# Searching students
def search_student(search):
"""A function that takes a name we input and then search students"""
searched_student = 0
print("Student name | ID | Math | Eng | Phy | EmTech | Incl | CME | HPE | GPA |")
for student in students:
if student["firstname"].startswith(search):
for value in student.values():
print(value, end=" | ")
print()
searched_student +=1
if searched_student == 0:
print("\nNo student with this name.\n")
def all_student_info_update(student, updated_fname, updated_lname, updated_mathematics, updated_english, updated_physics, updated_em_tech, updated_inclusiveness, updated_cme, updated_hpe):
"""This function update all student informations"""
student["firstname"] = updated_fname
student["lastname"] = updated_lname
student["mathematics"] = updated_mathematics
student["english"] = updated_english
student["physics"] = updated_physics
student["em_tech"] = updated_em_tech
student["inclusiveness"] = updated_inclusiveness
student["civic"] = updated_cme
student["hpe"] = updated_hpe
def update_student_name(student, updated_fname, updated_lname):
"""Updates only name of student"""
student["firstname"] = updated_fname
student["lastname"] = updated_lname
def update_all_score(student, updated_mathematics, updated_english, updated_physics, updated_em_tech, updated_inclusiveness, updated_cme, updated_hpe):
"""updates student scores all in once."""
student["mathematics"] = updated_mathematics
student["english"] = updated_english
student["physics"] = updated_physics
student["em_tech"] = updated_em_tech
student["inclusiveness"] = updated_inclusiveness
student["civic"] = updated_cme
student["hpe"] = updated_hpe
def update_id(student, new_id):
"""updates ID of student"""
student["ID"] = new_id
def delete_student(id_to_delete):
"""A function to delete students"""
for index, stud in enumerate(students):
if id_to_delete == students[index]["ID"]:
del students[index]
print(f"You removed a student successfully.\n")
managing_student = True
while managing_student:
print("1. Add students")
print("2. View students")
print("3. Search students")
print("4. Update students")
print("5. Delete students")
print("6. Grade Calculator")
print("7. Exit")
user_input = input("Enter a number to work on: ")
if user_input == "1":
# Asks students for information
adding_student = True
while adding_student:
first_name = input("Enter firstname: ").lower()
last_name = input("Enter lastname: ").lower()
entering_id = True
while entering_id:
id = input("Enter student ID no: ")
# this counts how many times the user entered id that was occupied by another student. sets to zero everytime the loop rotates
tried_id = 0
# # Checks if there is student in a list
# if len(students) > 0:
# finds whether there is the same id with the user is entering and asks user to enter new id.
for student in students:
if id == student["ID"]:
print("There is another student with this ID")
tried_id +=1
# If id is not occupied it passes to next question
if tried_id <= 0:
break
# else:
# break
print("\nWhen you enter scores it have to be between 0 and 100. \n\tIf not, calculation will be wrong.")
mathematics = float(input("Enter Mathematics Score: "))
english = float(input("Enter English score: "))
physics = float(input("Enter Physics score: "))
em_tech = float(input("Enter Emerging Technology score: "))
inclusiveness = float(input("Enter Inclusiveness score: "))
cme = float(input("Enter CME score: "))
print("\nhpe score will not be included in your mark. It is just there for practice. \n\ttype 'n' if you don't know your mark here.")
hpe = float(input("Enter hpe score: "))
if hpe not in range(1, 101):
hpe = "unknown"
# Calling a function to store students information
add_students(first_name,last_name, id, mathematics, english, physics, em_tech, inclusiveness, cme, hpe)
# Calling grade calculator function
students[student_index]["GPA"] = student_grade([mathematics, english, physics, em_tech, inclusiveness, cme], credit_total, credit_point_of_subjects)
# Increase students index by 1 inorder to add GPA to next student
student_index +=1
# Ask a student wether he want to add new student or not
new_student = input("Are you going to add new Student? type 'y' or 'n'. ")
if new_student == 'n':
break
# Used to view added students
if user_input == "2":
if len(students) > 0:
print("\nList of Students")
list_of_students()
else:
print("No added students to view.\n")
# Used to search student
if user_input == "3":
# Checks if there is any student in students. if not it will not search.
if len(students) > 0:
# ask first name to search
search = input("Enter first name of student to search: ").lower()
search_student(search)
else:
print("You cannot search from empty student.\n")
if user_input == "4":
# I use this variable to check if an ID a user entered is located
updated_id_amount = 0
if len(students) > 0:
list_of_students()
id_to_update = input("Enter id of student you wanted to update: ")
for student_indx, student_info in enumerate(students):
if id_to_update == student_info["ID"]:
updated_id_amount +=1
print("1. All information(without ID number)")
print("2. Name")
print("3. Scores")
print("4. ID")
info_to_update = input("Which data do you want to update? enter a number: ")
if info_to_update == "1":
new_firstname = input("Enter new name: ").lower()
new_lastname = input("Enter new lastname: ").lower()
new_math_score = float(input("Enter new Mathematics score: "))
new_eng_score = float(input("Enter new English score: "))
new_phy_score = float(input("Enter new Physics score: "))
new_em_tech_score = float(input("Enter new Emerging Technology score: "))
new_incl_score = float(input("Enter new Inclusiveness score: "))
new_civic_score = float(input("Enter new Civic and Moral Education score: "))
new_hpe_score = float(input("Enter new Physical Fitness score: "))
# Call to update all informations
all_student_info_update(student_info, new_firstname, new_lastname, new_math_score, new_eng_score, new_phy_score, new_em_tech_score, new_incl_score, new_civic_score, new_hpe_score)
# Calling a GPA to correct the previous GPA to the one updated
student_info["GPA"] = student_grade([new_math_score, new_eng_score, new_phy_score, new_em_tech_score, new_incl_score, new_civic_score], credit_total, credit_point_of_subjects)
if info_to_update == "2":
new_student_firstname = input("Enter new firstname: ").lower()
new_student_lastname = input("Enter new lastname: ").lower()
update_student_name(student_info, new_student_firstname, new_student_lastname)
if info_to_update == "3":
print("00. All score")
print("1. Mathemathics score")
print("2. English score")
print("3. Physics score")
print("4. Emerging Technology score")
print("5. Inclusiveness score")
print("6. Civic and Moral Education score")
print("7. Physical Fitness score")
score_to_update = input("Which score do you want to update? Enter a number: ")
if score_to_update == "00":
new_mathematics_score = float(input("Enter new Mathematics score: "))
new_english_score = float(input("Enter new English score: "))
new_physics_score = float(input("Enter new Physics score: "))
new_emerging_tech_score = float(input("Enter new Emerging Technology score: "))
new_inclusiveness_score = float(input("Enter new Inclusiveness score: "))
new_cme_score = float(input("Enter new Civic and Moral Education score: "))
new_PE_score = float(input("Enter new Physical Fitness score: "))
update_all_score(student_info, new_mathematics_score, new_english_score, new_physics_score, new_emerging_tech_score, new_inclusiveness_score, new_cme_score, new_PE_score)
# Calling a GPA to correct the previous GPA to the one updated
student_info["GPA"] = student_grade([new_mathematics_score, new_english_score, new_physics_score, new_emerging_tech_score, new_inclusiveness_score, new_cme_score], credit_total, credit_point_of_subjects)
if score_to_update == "1":
new_maths_score = float(input("Enter new Mathematics score: "))
student_info["mathematics"] = new_maths_score
# Calling a GPA to correct the previous GPA to the one updated
student_info["GPA"] = student_grade([new_maths_score, student_info["english"], student_info["physics"], student_info["em_tech"], student_info["inclusiveness"], student_info["civic"]], credit_total, credit_point_of_subjects)
if score_to_update == "2":
new_englz_score = float(input("Enter new English score: "))
student_info["english"] = new_englz_score
# Calling a GPA to correct the previous GPA to the one updated
student_info["GPA"] = student_grade([student_info["mathematics"], new_englz_score, student_info["physics"], student_info["em_tech"], student_info["inclusiveness"], student_info["civic"]], credit_total, credit_point_of_subjects)
if score_to_update == "3":
new_physc_score = float(input("Enter new Physics score: "))
student_info["physics"] = new_physc_score
# Calling a GPA to correct the previous GPA to the one updated
student_info["GPA"] = student_grade([student_info["mathematics"], student_info["english"], new_physc_score, student_info["em_tech"], student_info["inclusiveness"], student_info["civic"]], credit_total, credit_point_of_subjects)
if score_to_update == "4":
new_emerg_tech_score = float(input("Enter new Emerging Technology score: "))
student_info["em_tech"] = new_emerg_tech_score
# Calling a GPA to correct the previous GPA to the one updated
student_info["GPA"] = student_grade([student_info["mathematics"], student_info["english"], student_info["physics"], new_emerg_tech_score, student_info["inclusiveness"], student_info["civic"]], credit_total, credit_point_of_subjects)
if score_to_update == "5":
new_inclsv_score = float(input("Enter new Inclusiveness score: "))
student_info["inclusiveness"] = new_inclsv_score
# Calling a GPA to correct the previous GPA to the one updated
student_info["GPA"] = student_grade([student_info["mathematics"], student_info["english"], student_info["physics"], student_info["em_tech"], new_inclsv_score, student_info["civic"]], credit_total, credit_point_of_subjects)
if score_to_update == "6":
new_civics_score = float(input("Enter new Civics score: "))
student["civic"] = new_civics_score
# Calling a GPA to correct the previous GPA to the one updated
student_info["GPA"] = student_grade([student_info["mathematics"], student_info["english"], student_info["physics"], student_info["em_tech"], student_info["inclusiveness"], new_civics_score], credit_total, credit_point_of_subjects)
if score_to_update == "7":
new_phy_fitness_score = float(input("Enter new Physical Fitness score: "))
student_info["hpe"] = new_phy_fitness_score
if info_to_update == "4":
changing_id = True
while changing_id:
# Checks if any ID that a user is modifying to exists in a data and decline change if exists
exist_id = 0
new_id = input("Enter new ID: ")
if new_id == student_info["ID"]:
print("Your ID is same as the before ID.\n")
break
for index, student_inf in enumerate(students):
if student_inf["ID"] == new_id:
exist_id +=1
if exist_id == 0:
update_id(student, new_id)
break
if exist_id >= 1:
print("You are entering another student ID. please try again\n")
if updated_id_amount <= 0:
print("No ID that is the same with the ID you entered.\n")
else:
print("There is no student in a list to update.\n")
# Deletes students with their id
if user_input == "5":
# This will store id to check it for if there is ID to be deleted. I use ID stored in this later to reply there is no student with this ID
deleted_id = []
if len(students) > 0:
print("\nList of Students.")
list_of_students()
print()
student_to_delete = input("Enter a id of student you wanted to delete: ")
for index, stud in enumerate(students):
if student_to_delete == students[index]["ID"]:
deleted_id.append(student_to_delete)
delete_student(student_to_delete)
# reduce students len by 1 after deleting a student
student_index -=1
if len(deleted_id) <= 0:
print("You entered an ID that is not in a list.")
else:
print("No Students to delete.\n")
# Calculates grade of students
if user_input == "6":
math = float(input("Enter Mathematics score: "))
eng = float(input("Enter English score: "))
phy = float(input("Enter Physics score: "))
em_tech = float(input("Enter Emerging Technology score: "))
inclusiveness_subj = float(input("Enter Inclusiveness score: "))
civic = float(input("Enter Civic and Moral Education score: "))
calculated_gpa = student_grade([math, eng, phy, em_tech, inclusiveness_subj, civic], credit_total, credit_point_of_subjects)
print(f"Your GPA is {round(calculated_gpa, 2)}\n")
if user_input == "7":
for student in students:
print(student)
print("Your app has been closed.")
break