Mini Python Project | Dataplexa

Mini Python Project: Student Report Generator

You have officially completed all 45 lessons of the Dataplexa Python Course — an amazing achievement! In this final lesson, you will build a complete beginner-friendly project that brings together variables, loops, lists, dictionaries, calculations, functions, and file handling.

This project is designed so that even a non-IT learner can understand how a real Python program is structured and executed.

📌 Project Overview

The program will:

  • Collect student details
  • Accept multiple subject marks
  • Calculate total, average, and grade
  • Display a formatted report
  • Save the report into a file

📘 Step 1: Collect Student Information

We begin by storing basic student details. Input is very useful because it makes programs interactive and customizable.

name = input("Enter student name: ")
student_id = input("Enter student ID: ")

📘 Step 2: Enter Subject Marks

Using a loop allows the user to add any number of subjects. This is a great demonstration of dynamic data collection.

subjects = {}
count = int(input("How many subjects? "))

for i in range(count):
    subject = input(f"Enter subject {i+1} name: ")
    marks = float(input(f"Enter marks for {subject}: "))
    subjects[subject] = marks

📘 Step 3: Calculate Total, Average & Grade

Once all marks are collected, we compute the student’s performance. Calculations like these are common in grading systems.

total = sum(subjects.values())
average = total / len(subjects)

if average >= 90:
    grade = "A"
elif average >= 80:
    grade = "B"
elif average >= 70:
    grade = "C"
elif average >= 60:
    grade = "D"
else:
    grade = "F"

📘 Step 4: Display the Report

We now print a clear, readable report. Formatting matters because users must easily understand the output.

print("\n----- STUDENT REPORT -----")
print("Name:", name)
print("Student ID:", student_id)

print("\nMarks:")
for subject, score in subjects.items():
    print(f"{subject}: {score}")

print("\nTotal Marks:", total)
print("Average Score:", round(average, 2))
print("Grade:", grade)

📘 Step 5: Save the Report to a File

Saving results is a key step in real-world applications such as student portals, billing systems, and analytics dashboards.

with open("student_report.txt", "w") as file:
    file.write("----- STUDENT REPORT -----\n")
    file.write(f"Name: {name}\n")
    file.write(f"Student ID: {student_id}\n\n")

    file.write("Marks:\n")
    for subject, score in subjects.items():
        file.write(f"{subject}: {score}\n")

    file.write(f"\nTotal Marks: {total}\n")
    file.write(f"Average Score: {round(average, 2)}\n")
    file.write(f"Grade: {grade}\n")

print("Report saved successfully!")

📘 Full Project Code

Here is the complete program for learners who want to study the entire flow in one place.

# Mini Python Project: Student Report Generator

name = input("Enter student name: ")
student_id = input("Enter student ID: ")

subjects = {}
count = int(input("How many subjects? "))

for i in range(count):
    subject = input(f"Enter subject {i+1} name: ")
    marks = float(input(f"Enter marks for {subject}: "))
    subjects[subject] = marks

total = sum(subjects.values())
average = total / len(subjects)

if average >= 90:
    grade = "A"
elif average >= 80:
    grade = "B"
elif average >= 70:
    grade = "C"
elif average >= 60:
    grade = "D"
else:
    grade = "F"

print("\n----- STUDENT REPORT -----")
print("Name:", name)
print("Student ID:", student_id)

print("\nMarks:")
for subject, score in subjects.items():
    print(f"{subject}: {score}")

print("\nTotal Marks:", total)
print("Average Score:", round(average, 2))
print("Grade:", grade)

with open("student_report.txt", "w") as file:
    file.write("----- STUDENT REPORT -----\n")
    file.write(f"Name: {name}\n")
    file.write(f"Student ID: {student_id}\n\n")

    file.write("Marks:\n")
    for subject, score in subjects.items():
        file.write(f"{subject}: {score}\n")

    file.write(f"\nTotal Marks: {total}\n")
    file.write(f"Average Score: {round(average, 2)}\n")
    file.write(f"Grade: {grade}\n")

print("Report saved successfully!")

📝 Practice Exercises


Exercise 1

Modify the project to also calculate the highest and lowest marks.

Exercise 2

Add a feature where scores above 95 get an “A+” grade.

Exercise 3

Save each student report using the student name in the file name.

Exercise 4

Allow the program to process multiple students and compute a class average.


✅ Practice Answers


Answer 1

highest = max(subjects.values())
lowest = min(subjects.values())

print("Highest Score:", highest)
print("Lowest Score:", lowest)

Answer 2

if average >= 95:
    grade = "A+"
elif average >= 90:
    grade = "A"

Answer 3

filename = f"{name}_report.txt"
with open(filename, "w") as file:
    file.write("Student Report Saved")

Answer 4

averages = [78, 92, 85, 88]
class_avg = sum(averages) / len(averages)
print("Class Average:", class_avg)