0% found this document useful (0 votes)
7 views3 pages

Python Assignment

The document contains a Python script for calculating and storing student grades and GPA. It includes functions to convert letter grades to grade points, as well as methods to input student data and output results to a file. The script also demonstrates different approaches to handle grade input and GPA calculation for multiple students.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views3 pages

Python Assignment

The document contains a Python script for calculating and storing student grades and GPA. It includes functions to convert letter grades to grade points, as well as methods to input student data and output results to a file. The script also demonstrates different approaches to handle grade input and GPA calculation for multiple students.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

# Making Result sheet using file.

def checkGP(grade):
if grade=="A":
return 5
elif grade=="B":
return 4
elif grade=="C":
return 3
elif grade=="D":
return 2
else:
return 0

output_file = open('[Link]', 'w') # Opening the file

for i in range(0,3):
name = input("Enter name of student: ")

bangla_grade = input("Enter Bangla grade: ")


english_grade = input("Enter English grade: ")
math_grade = input("Enter Math grade: ")

bangla_grade_point = checkGP(bangla_grade)
english_grade_point = checkGP(english_grade)
math_grade_point = checkGP(math_grade)

output_file.write("Name: %s\n"%name)
output_file.write("Subject\t\tGrade\t\tGrade Point\n")
output_file.write("Bangla\t\t%s\t\t%f\n"%(bangla_grade,bangla_grade_point))
output_file.write("English\t\t%s\t\t%f\n"%(english_grade,english_grade_point)
)
output_file.write("Math\t\t%s\t\t%f\n"%(math_grade,math_grade_point))
output_file.write("GPA: %.2f\n"%((bangla_grade_point + english_grade_point +
math_grade_point)/3))
output_file.write("\n")

output_file.close() # Closing the file


# Create empty lists to store student data
students = []
grades = []

for i in range(3):
name = input("Enter name of student: ")
bangla_grade = input("Enter Bangla grade of %s (A+/A/A-/B/C/D): "%name)
english_grade = input("Enter English grade %s (A+/A/A-/B/C/D): "%name)
math_grade = input("Enter Math grade %s (A+/A/A-/B/C/D): "%name)

student_data = [name, bangla_grade, english_grade, math_grade]


[Link](student_data)

grade_points = []
for grade in [bangla_grade, english_grade, math_grade]:
if grade == 'A+':
grade_points.append(5)
elif grade == 'A':
grade_points.append(4)
elif grade == 'A-':
grade_points.append(3.5)
elif grade == 'B':
grade_points.append(3)
elif grade == 'C':
grade_points.append(2)
elif grade == 'D':
grade_points.append(1)
else:
grade_points.append(0)
[Link](grade_points)

for i in range(3):
print("Student Name: ", students[i][0])
print("Subject Grade Grade Point")
print("Bangla ", students[i][1], " ", grades[i][0])
print("English ", students[i][2], " ", grades[i][1])
print("Math ", students[i][3], " ", grades[i][2])
print("GPA: %.2f{sum(grades[i])/3)}")
print("\n")
# Define a dictionary to store the grades and grade points for each letter grade
grade_scale = {
'A': {'grade_points': 4.0},
'B': {'grade_points': 3.0},
'C': {'grade_points': 2.0},
'D': {'grade_points': 1.0},
'F': {'grade_points': 0.0}
}

students = {}
for i in range(3):
name = input("Enter name of student: ")

grades = {}
for subject in ['Bangla', 'English', 'Math']:
grade = input("Enter grade for %s(A+/A/A-/B/C/D/F): "%subject)
grades[subject] = [grade,grade_scale.get([Link]())]
students[name] = grades

for name, grades in [Link]():


print("\nStudent Name: %s "%name)
print("Subject Grade Grade Point")
GPA=0
for subject, grade in [Link]():
print("%s \t"%subject,end="")
for i in grade:
if type(i) is dict:
print(i['grade_points'])
GPA=GPA+i['grade_points']
else:
print("%s "%i,end="")

GPA=GPA/3
print("GPA: %s "%GPA)

You might also like