Python Code Sample

We were tasked with creating a student repository system that generates informative reports in a tabular format.

Here's what we aimed to accomplish:

  • List of All Students: Displaying student data in a clear report format without any calculations.

  • Academic Standings: Providing an overview of students' academic standings, including Dean’s list status, probation, and their corresponding GPA.

  • STEM Student Majors and Minors: Identifying and listing majors and minors for students designated as STEM majors.

  • Non-STEM Student Majors and Minors: Similarly, listing majors and minors for students not designated as STEM majors.

  • Student Financials: Detailing students' in-state or out-of-state status, STEM designation, credits completed, credits remaining for their degree, tuition paid so far, and tuition required to complete their degree.

  • Custom Report: Crafting an additional report of our choice, ensuring clarity and relevance in addressing academic needs.

#Shruthie Ramasamy

#Final Project, Student Information System Functions

#ICS 698

#Spring-2023

#This program displays different versions of a student repository

#The main menu will introduce the user to the report options

#Once user enters their input the report will display

#You will have the menu option again

#User can pull up another report or exit the program

#Importing pie chart module

import matplotlib.pyplot as plt

#Creating introduction

def intro():

print('Hello Professor!')

print('Welcome to the Student Information System Functions!')

#Creating your main menu

def main_menu():

print('========================================')

print('{:>25}'.format('Main Menu'))

print('========================================')

print('1 - List of Students')

print('2 - List of Students\' Academic Standings')

print('3 - List of Majors and Minors of STEM students')

print('4 - List of Majors and Minors of non-STEM students')

print('5 - List of Student\'s State status, Tuition paid, Tuition to-be paid, STEM designation, Credits completed, and Credits required')

print('6 - List of Student\'s gender and pie chart')

print('7- Exit')

print('========================================')

report = input('Please enter the report you want to pull up: ')

print('')

display_report(report) #passing report selection into display function

#Creating different reports

def display_report(report):

#opening to read text file

with open('Data_Final_Project.txt', 'r') as file:

lines = file.readlines()

students = [] #creating empty list

#Report one displays student name and serial number

if report == '1':

for line in lines: #reading the lines

data = line.split(',') #split lines using commas

first_name = data[0].strip() #selecting column 0 as first name and removing spaces

last_name = data[1].strip() #selecting column 1 as last name and removing spaces

student_id = data[2].strip() #selecting column 2 as student id column

students.append((student_id, first_name, last_name)) #add names to list

print('{:<15}{:<15}{:<15}'.format('Student ID', 'First Name', 'Last Name')) #format header

print('=' * 50)

for student in students: #format table content

print('{:<15}{:<15}{:<15}'.format(student[0], student[1], student[2]))

main_menu() #user can pull up another report or exit

#Report two displays student names,gpa and academic standings

elif report == '2':

for line in lines:

data = line.strip().split(',')

first_name = data[0].strip()

last_name = data[1].strip()

student_id = data[2].strip()

gpa = float(data[8].strip()) #selecting column 8 to display gpa in float format

#categorise academic standings

if gpa >= 3.75:

standing = "Dean's List"

elif gpa >= 3.50:

standing = "Honor's List"

elif gpa >= 2.00:

standing = "Normal Academic Standing"

else:

standing = "On Probation"

students.append((student_id, first_name, last_name, gpa, standing))

print('{:<15}{:<15}{:<15}{:<10}{:<25}'.format('Student ID', 'First Name', 'Last Name', 'GPA', 'Academic Standing')) #format header

print('=' * 80)

for student in students:#format table content

print('{:<15}{:<15}{:<15}{:<10.2f}{:<25}'.format(student[0], student[1], student[2], student[3], student[4]))

main_menu()

#Report three displays STEM students major and minors

elif report == '3':

for line in lines:

data = line.strip().split(',')

first_name = data[0].strip()

last_name = data[1].strip()

student_id = data[2].strip()

major = data[6].strip() #selecting column 6 as major

minor = data[7].strip() #selecting column 7 as minor

STEM_designation = data[10].strip() #selecting column 10 for STEM designation

if STEM_designation == '1':

stem_major = major #assigning only STEM student majors

stem_minor = minor #assigning only STEM student minors

students.append([student_id, first_name, last_name, stem_major, stem_minor])

print('{:<15}{:<15}{:<15}{:<15}{:<80}'.format('Student ID', 'First Name', 'Last Name', 'Major', 'Minor'))

print('=' * 90)

for student in students:

print('{:<15}{:<15}{:<15}{:<15}{:<80}'.format(student[0], student[1], student[2], student[3], student[4]))

main_menu()

#Report four displays non-STEM student majors and minors

elif report == '4':

for line in lines:

data = line.strip().split(',')

first_name = data[0].strip()

last_name = data[1].strip()

student_id = data[2].strip()

major = data[6].strip()

minor = data[7].strip()

STEM_designation = data[10].strip()

if STEM_designation == '0': #non-stem student

nonstem_major = major #assigning only non-STEM student majors

nonstem_minor = minor #assigning only non-STEM student minors

students.append([student_id, first_name, last_name, nonstem_major, nonstem_minor])

print('{:<15}{:<15}{:<15}{:<15}{:<15}'.format('Student ID', 'First Name', 'Last Name', 'Major', 'Minor'))

print('=' * 70)

for student in students:

print('{:<15}{:<15}{:<15}{:<15}{:<15}'.format(student[0], student[1], student[2], student[3], student[4],))

main_menu()

#Report five displays state status, tuition paid, tuition to-be-paid, credits completed, and credits to-be-completed

elif report == '5':

for line in lines:

data = line.strip().split(',')

first_name = data[0].strip()

last_name = data[1].strip()

student_id = data[2].strip()

student_location = data[5].strip() #selecting column 7 as student location

STEM_designation = data[10].strip()

credits_attempted = int(data[9].strip()) #selecting column 9 as credits completed in numerical format

credits_required = 120 - credits_attempted #assuming is 120 credits is needed to complete degree

if student_location == '1':

state = 'In-state' #display in-state if text file shows 1120 is the total number of credits to complete

if STEM_designation == '1':

tuition_paid = credits_attempted * 350 #in-state STEM cost 350

tuition_pending = credits_required * 350

else:

tuition_paid = credits_attempted * 325 #in-state non-STEM cost is 350

tuition_pending = credits_required * 325

else:

state = 'Out-of-state' #display out-of-state if text file shows 0

if STEM_designation == '1':

tuition_paid = credits_attempted * 675 #out-of-state STEM cost is 675

tuition_pending = credits_required * 675

else:

tuition_paid = credits_attempted * 650 #out-of-state non-STEM cost is 650

tuition_pending = credits_required * 650

students.append([student_id, first_name, last_name, state, credits_attempted, tuition_paid,credits_required, tuition_pending])

print('{:<15}{:<15}{:<15}{:<15}{:<15}{:<20}{:<30}{:<20}'.format('Student ID', 'First Name', 'Last Name', 'State Status', 'Credits Complete ', ' Tuition Paid ', ' Credits Required', 'Tuition Pending'))

print('=' * 150)

for student in students:

print('{:<15}{:<15}{:<20}{:<20}{:<20}{:<15}{:<20}{:<15}'.format(student[0], student[1], student[2], student[3], student[4], '$'+str(student[5]), student[6], '$'+str(student[7])))

main_menu()

#Report six displays a pie chart and table of student genders

elif report == '6':

male_count = 0 #Male count at 0

female_count = 0 #Female count at 0

for line in lines:

data = line.strip().split(',')

first_name = data[0].strip()

last_name = data[1].strip()

gender = data[3].strip() #selecting column 3 as gender

students.append([first_name, last_name, gender]) #list 1 created

if gender == 'M':

male_count += 1 #add to male count when there is a M

elif gender == 'F':

female_count += 1 #add to female count when there is a F

for student in students: #adding another column that displays male or female

gender = student[2]

if gender == 'M':

student.append('Male') #replace M from the list with Male

elif gender == 'F':

student.append('Female') #replace F from the list as female

#Create pie chart

labels = ['Male', 'Female']

sizes = [male_count, female_count]

if male_count != 0 or female_count != 0:

fig1, ax1 = plt.subplots()

ax1.pie(sizes, labels=labels, autopct='%1.1f%%', startangle=90)

ax1.axis('equal')

plt.show()

print('{:<15}{:<15}{:<15}'.format('First Name', 'Last Name', 'Gender'))

print('=' * 50)

for student in students:

print('{:<15}{:<15}{:<15}'.format(student[0], student[1], student[3])) #Since we do not want to see M or F we did not display column 2 from list 1

main_menu()

#Report seven exits the program

elif report == '7':

print('Thank you for visiting the student repository!')

print('Have a great day!')

sis_func

Previous
Previous

Case Study Analysis