Last active
June 24, 2025 11:57
-
-
Save shinysu/a00d0e5283024755b34fb0b5d353b730 to your computer and use it in GitHub Desktop.
student_marksheet
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Get the marks of a student and print the result based on the marks. | |
# getting input, print, functions, conditionals | |
def pass_or_fail(marks): | |
if marks >= 40: | |
return "Pass" | |
else: | |
return "Fail" | |
name = input("Enter the student's name: ") | |
marks = int(input(f"Enter marks for subject {i + 1}: ")) | |
result = pass_or_fail(marks) | |
print(result) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Get the marks of a student and print the result and grade based on the marks. | |
# if-elif-else | |
def pass_or_fail(marks): | |
if marks >= 40: | |
return "Pass" | |
else: | |
return "Fail" | |
def get_grade(marks): | |
if marks >= 90: | |
return "A+" | |
elif marks >= 80: | |
return "A" | |
elif marks >= 70: | |
return "B+" | |
elif marks >= 60: | |
return "B" | |
elif marks >= 50: | |
return "C" | |
elif marks >= 40: | |
return "D" | |
else: | |
return "F" | |
name = input("Enter the student's name: ") | |
marks = int(input(f"Enter marks for subject: ")) | |
result = pass_or_fail(marks) | |
print("Result:",result) | |
grade = get_grade(marks) | |
print("Grade:",grade) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Get the marks of a student in 6 subjects and print the result and grade | |
# loops | |
def pass_or_fail(marks): | |
if marks >= 40: | |
return "Pass" | |
else: | |
return "Fail" | |
def get_grade(marks): | |
if marks >= 90: | |
return "A+" | |
elif marks >= 80: | |
return "A" | |
elif marks >= 70: | |
return "B+" | |
elif marks >= 60: | |
return "B" | |
elif marks >= 50: | |
return "C" | |
elif marks >= 40: | |
return "D" | |
else: | |
return "F" | |
name = input("Enter the student's name: ") | |
for i in range(6): | |
marks = int(input(f"Enter marks for subject {i + 1}: ")) | |
status = pass_or_fail(marks) | |
print(status) | |
grade = get_grade(marks) | |
print(grade) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Get the marks of a student in 6 subjects and print the result and grade | |
# list, string formatting | |
marklist = [] | |
def pass_or_fail(marks): | |
if marks >= 40: | |
return "Pass" | |
else: | |
return "Fail" | |
def get_grade(marks): | |
if marks >= 90: | |
return "A+" | |
elif marks >= 80: | |
return "A" | |
elif marks >= 70: | |
return "B+" | |
elif marks >= 60: | |
return "B" | |
elif marks >= 50: | |
return "C" | |
elif marks >= 40: | |
return "D" | |
else: | |
return "F" | |
name = input("Enter the student's name: ") | |
for i in range(6): | |
mark = int(input(f"Enter marks for subject {i + 1}: ")) | |
marklist.append(mark) | |
print(f"\nMarksheet for {name}") | |
print(f"--------------------------------") | |
print(f"Marks \t Status \t Grade") | |
for mark in marklist: | |
status = pass_or_fail(mark) | |
grade = get_grade(mark) | |
# print(f"Marks: {mark}, Status: {status}, Grade: {grade}") | |
print(f"{mark} \t {status} \t\t {grade}") | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Print the subject name as well for the marksheet | |
# difficulty of having subjects in a list | |
marklist = [] | |
subjects = ["Math", "English", "Tamil", "Physics", "Chemistry" "Computer Science"] | |
def pass_or_fail(marks): | |
if marks >= 40: | |
return "Pass" | |
else: | |
return "Fail" | |
def get_grade(marks): | |
if marks >= 90: | |
return "A+" | |
elif marks >= 80: | |
return "A" | |
elif marks >= 70: | |
return "B+" | |
elif marks >= 60: | |
return "B" | |
elif marks >= 50: | |
return "C" | |
elif marks >= 40: | |
return "D" | |
else: | |
return "F" | |
name = input("Enter the student's name: ") | |
for subject in subjects: | |
mark = int(input(f"Enter marks for subject {subject}: ")) | |
marklist.append(mark) | |
print(f"\nMarksheet for {name}") | |
print(f"--------------------------------") | |
print(f"Marks \t Status \t Grade") | |
for mark in marklist: | |
status = pass_or_fail(mark) | |
grade = get_grade(mark) | |
# print(f"Marks: {mark}, Status: {status}, Grade: {grade}") | |
print(f"{mark} \t {status} \t\t {grade}") | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Use dictionary for storing marks | |
# dictionary with key as string and value as number, formatting, functions returning values | |
# Example: | |
# marklist = { | |
# "Math": 60, | |
# "English": 70, | |
# "Tamil": 50, | |
# "Physics": 60, | |
# "Chemistry": 40, | |
# "Computer": 80 | |
# } | |
marklist = {} | |
subjects = ["Math", "English", "Tamil", "Physics", "Chemistry", "Computer"] | |
def pass_or_fail(marks): | |
if marks >= 40: | |
return "Pass" | |
else: | |
return "Fail" | |
def get_grade(marks): | |
if marks >= 90: | |
return "A+" | |
elif marks >= 80: | |
return "A" | |
elif marks >= 70: | |
return "B+" | |
elif marks >= 60: | |
return "B" | |
elif marks >= 50: | |
return "C" | |
elif marks >= 40: | |
return "D" | |
else: | |
return "F" | |
def print_header(name): | |
print(f"\nMarksheet for {name}") | |
print("-" * 50) | |
print("Subject".ljust(15) + "Marks".rjust(8) + " " + "Status".center(10) + " " + "Grade".center(10)) | |
print("-" * 50) | |
def get_input(): | |
name = input("Enter the student's name: ") | |
for subject in subjects: | |
mark = int(input(f"Enter marks for subject {subject}: ")) | |
marklist[subject] = mark | |
return name, marklist | |
def print_marks(marklist): | |
for subject, mark in marklist.items(): | |
status = pass_or_fail(mark) | |
grade = get_grade(mark) | |
print(subject.ljust(15) + str(mark).rjust(8) + " " + status.center(10) + " " + grade.center(10)) | |
name, marklist = get_input() | |
print_header(name) | |
print_marks(marklist) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Exercise: Find overall result and print it at the end of the marksheet. | |
# global variable | |
result = "Pass" # default result | |
subjects = ["Math", "English", "Tamil", "Physics", "Chemistry", "Computer"] | |
def pass_or_fail(marks): | |
if marks >= 40: | |
return "Pass" | |
else: | |
return "Fail" | |
def get_grade(marks): | |
if marks >= 90: | |
return "A+" | |
elif marks >= 80: | |
return "A" | |
elif marks >= 70: | |
return "B+" | |
elif marks >= 60: | |
return "B" | |
elif marks >= 50: | |
return "C" | |
elif marks >= 40: | |
return "D" | |
else: | |
return "F" | |
def print_header(name): | |
print(f"\nMarksheet for {name}") | |
print("-" * 50) | |
print("Subject".ljust(15) + "Marks".rjust(8) + " " + "Status".center(10) + " " + "Grade".center(10)) | |
print("-" * 50) | |
def get_input(): | |
marklist = {} | |
name = input("Enter the student's name: ") | |
for subject in subjects: | |
mark = int(input(f"Enter marks for subject {subject}: ")) | |
marklist[subject] = mark | |
return name, marklist | |
def print_marks(marklist): | |
global result | |
for subject, mark in marklist.items(): | |
status = pass_or_fail(mark) | |
if status == "Fail": | |
result = "Fail" | |
grade = get_grade(mark) | |
print(subject.ljust(15) + str(mark).rjust(8) + " " + status.center(10) + " " + grade.center(10)) | |
name, marklist = get_input() | |
print_header(name) | |
print_marks(marklist) | |
print("-" * 50) | |
print(f"\nOverall Result: {result}\n") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Get marks for multiple students | |
# dictionary with key as string and value as dictionary | |
# | |
# Example: | |
# all_students = { | |
# "Alice": {"Math": 85, "English": 78, "Tamil": 90, "Physics": 88, "Chemistry": 92, "Computer": 95}, | |
# "Bob": {"Math": 45, "English": 55, "Tamil": 60, "Physics": 50, "Chemistry": 70, "Computer": 65}, | |
# "Charlie": {"Math": 95, "English": 88, "Tamil": 92, "Physics": 85, "Chemistry": 90, "Computer": 80} | |
# } | |
all_students = {} | |
subjects = ["Math", "English", "Tamil", "Physics", "Chemistry", "Computer"] | |
def pass_or_fail(marks): | |
if marks >= 40: | |
return "Pass" | |
else: | |
return "Fail" | |
def get_grade(marks): | |
if marks >= 90: | |
return "A+" | |
elif marks >= 80: | |
return "A" | |
elif marks >= 70: | |
return "B+" | |
elif marks >= 60: | |
return "B" | |
elif marks >= 50: | |
return "C" | |
elif marks >= 40: | |
return "D" | |
else: | |
return "F" | |
def print_header(name): | |
print(f"\nMarksheet for {name}") | |
print("-" * 50) | |
print("Subject".ljust(15) + "Marks".rjust(8) + " " + "Status".center(10) + " " + "Grade".center(10)) | |
print("-" * 50) | |
def get_input(): | |
class_strength = int(input("Enter the number of students: ")) | |
for i in range(class_strength): | |
marklist = {} | |
name = input(f"Enter the name of student {i + 1}: ") | |
for subject in subjects: | |
mark = int(input(f"Enter marks for subject {subject}: ")) | |
marklist[subject] = mark | |
all_students[name] = marklist | |
def print_marks(): | |
global result | |
for subject, mark in marklist.items(): | |
status = pass_or_fail(mark) | |
if status == "Fail": | |
result = "Fail" | |
grade = get_grade(mark) | |
print(subject.ljust(15) + str(mark).rjust(8) + " " + status.center(10) + " " + grade.center(10)) | |
get_input() | |
for name, marklist in all_students.items(): | |
result = "Pass" | |
print_header(name) | |
print_marks() | |
print("-" * 50) | |
print(f"\nOverall Result: {result}\n") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Get marks from the csv file | |
# read a csv file | |
import csv | |
all_students = {} | |
subjects = ["Math", "English", "Tamil", "Physics", "Chemistry", "Computer"] | |
def pass_or_fail(marks): | |
if marks >= 40: | |
return "Pass" | |
else: | |
return "Fail" | |
def get_grade(marks): | |
if marks >= 90: | |
return "A+" | |
elif marks >= 80: | |
return "A" | |
elif marks >= 70: | |
return "B+" | |
elif marks >= 60: | |
return "B" | |
elif marks >= 50: | |
return "C" | |
elif marks >= 40: | |
return "D" | |
else: | |
return "F" | |
def print_header(name): | |
print(f"\nMarksheet for {name}") | |
print("-" * 50) | |
print("Subject".ljust(15) + "Marks".rjust(8) + " " + "Status".center(10) + " " + "Grade".center(10)) | |
print("-" * 50) | |
def read_csv_data(filename): | |
with open(filename, newline='') as csvfile: | |
reader = csv.DictReader(csvfile) | |
for row in reader: | |
name = row["Name"] | |
marks = {subject: int(row[subject]) for subject in subjects} | |
all_students[name] = marks | |
def print_marks(): | |
global result | |
for subject, mark in marklist.items(): | |
status = pass_or_fail(mark) | |
if status == "Fail": | |
result = "Fail" | |
grade = get_grade(mark) | |
print(subject.ljust(15) + str(mark).rjust(8) + " " + status.center(10) + " " + grade.center(10)) | |
read_csv_data('marks.csv') | |
for name, marklist in all_students.items(): | |
result = "Pass" | |
print_header(name) | |
print_marks() | |
print("-" * 50) | |
print(f"\nOverall Result: {result}\n") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Name | Math | English | Tamil | Physics | Chemistry | Computer | |
---|---|---|---|---|---|---|---|
Alice | 85 | 78 | 90 | 88 | 92 | 95 | |
Bob | 45 | 55 | 60 | 50 | 70 | 65 | |
Charlie | 95 | 88 | 32 | 85 | 90 | 80 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment