0% found this document useful (0 votes)
6 views4 pages

Class 12 Python Mini Projects

Uploaded by

letmebecore
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)
6 views4 pages

Class 12 Python Mini Projects

Uploaded by

letmebecore
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

Python File Handling Mini Projects

1) Student Report Card System

Code:

n = int(input("Enter number of students: "))

file = open("[Link]", "w")

for i in range(n):

name = input("Enter name: ")

roll = input("Enter roll number: ")

marks = []

for j in range(5):

m = int(input(f"Enter marks for subject {j+1}: "))

[Link](m)

total = sum(marks)

percentage = total / 5

grade = "A" if percentage >= 80 else "B" if percentage >= 60 else "C"

[Link](f"{name},{roll},{percentage},{grade}\n")

[Link]()

print("\n--- Student Report Card ---")

file = open("[Link]", "r")

for line in file:

data = [Link]().split(",")

print(f"Name: {data[0]}, Roll: {data[1]}, Percentage: {data[2]}, Grade: {data[3]}")

[Link]()

------------------------------------------------------------

2) To-Do List Manager

Page 1
Python File Handling Mini Projects

def view_tasks():

with open("[Link]", "r") as file:

tasks = [Link]()

if not tasks:

print("No tasks found.")

else:

for i, task in enumerate(tasks, start=1):

print(f"{i}. {[Link]()}")

def add_task():

task = input("Enter task: ")

with open("[Link]", "a") as file:

[Link](task + "\n")

def delete_task():

view_tasks()

num = int(input("Enter task number to delete: "))

with open("[Link]", "r") as file:

tasks = [Link]()

[Link](num - 1)

with open("[Link]", "w") as file:

[Link](tasks)

while True:

print("\n1. View Tasks\n2. Add Task\n3. Delete Task\n4. Exit")

choice = input("Enter choice: ")

if choice == "1":

view_tasks()

elif choice == "2":

add_task()

elif choice == "3":

Page 2
Python File Handling Mini Projects

delete_task()

else:

break

------------------------------------------------------------

3) Word Counter in a File

filename = input("Enter file name: ")

with open(filename, "r") as file:

text = [Link]()

words = [Link]()

total_words = len(words)

total_chars = len(text)

freq = {}

for word in words:

freq[word] = [Link](word, 0) + 1

most_common = max(freq, key=[Link])

with open("[Link]", "w") as file:

[Link](f"Total Words: {total_words}\n")

[Link](f"Total Characters: {total_chars}\n")

[Link](f"Most Frequent Word: {most_common}\n")

print("Summary saved in [Link]")

------------------------------------------------------------

Page 3
Python File Handling Mini Projects

4) Simple Diary App

from datetime import datetime

while True:

print("\n1. Write Note\n2. View Notes\n3. Exit")

choice = input("Enter choice: ")

if choice == "1":

note = input("Write your note: ")

with open("[Link]", "a") as file:

[Link]([Link]().strftime("%Y-%m-%d %H:%M:%S") + " - " + note + "\n")

elif choice == "2":

with open("[Link]", "r") as file:

print("\n--- Diary Notes ---")

print([Link]())

else:

break

Page 4

You might also like