0% found this document useful (0 votes)
33 views5 pages

Timetable Management - Mansi 12tha

The document is a Python script for managing a school timetable system, allowing teachers to add or delete teachers and classes, generate timetables, and students to view their timetables. It includes functions for loading and saving data in JSON format, as well as menus for teacher and student interactions. The script handles user input and provides feedback for various operations while ensuring data integrity.

Uploaded by

mansi05madame
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views5 pages

Timetable Management - Mansi 12tha

The document is a Python script for managing a school timetable system, allowing teachers to add or delete teachers and classes, generate timetables, and students to view their timetables. It includes functions for loading and saving data in JSON format, as well as menus for teacher and student interactions. The script handles user input and provides feedback for various operations while ensuring data integrity.

Uploaded by

mansi05madame
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Source code

import random
import json

# File to store data


DATA_FILE = "timetable_data.json"

# Load existing data or initialize empty structure


def load_data():
try:
with open(DATA_FILE, "r") as file:
return json.load(file)
except FileNotFoundError:
return {"teachers": [], "classes": []}

# Save data back to file


def save_data(data):
with open(DATA_FILE, "w") as file:
json.dump(data, file, indent=4)

# Add teacher
def add_teacher(data):
try:
teacher = {
"id": int(input("Enter teacher ID: ")),
"name": input("Enter teacher name: "),
"subject": input("Enter subject: "),
"post": input("Enter post: "),
"salary": int(input("Enter salary: ")),
"classes": [int(input("Enter class teaching {}: ".format(i
+ 1))) for i in range(2)],
}
data["teachers"].append(teacher)
print("Teacher added successfully.")
except ValueError:
print("Invalid input. Please try again.")

# Delete teacher
def delete_teacher(data):
try:
teacher_id = int(input("Enter teacher ID to delete: "))
data["teachers"] = [t for t in data["teachers"] if t["id"] !=
teacher_id]
print("Teacher deleted successfully.")
except ValueError:
print("Invalid input. Please try again.")

# Add class
def add_class(data):
try:
new_class = {
"class": int(input("Enter class: ")),
"section": input("Enter section: "),
"class_type": input("Enter class type: "),
"subjects": {
"main": [input(f"Enter main subject {i + 1}: ") for i
in range(5)],
"additional": [input(f"Enter additional subject {i +
1}: ") for i in range(3)],
},
"periods": int(input("Enter number of periods: ")),
}
data["classes"].append(new_class)
print("Class added successfully.")
except ValueError:
print("Invalid input. Please try again.")

# Delete class
def delete_class(data):
try:
class_id = int(input("Enter class: "))
section = input("Enter section: ")
data["classes"] = [
c for c in data["classes"] if not (c["class"] == class_id
and c["section"] == section)
]
print("Class deleted successfully.")
except ValueError:
print("Invalid input. Please try again.")

# Generate timetable
def generate_timetable(data):
try:
class_id = int(input("Enter class: "))
section = input("Enter section: ")
target_class = next(
(c for c in data["classes"] if c["class"] == class_id and
c["section"] == section), None
)
if not target_class:
print("Class not found.")
return

subjects = target_class["subjects"]["main"] +
target_class["subjects"]["additional"]
timetable = {}
days = ["Monday", "Tuesday", "Wednesday", "Thursday",
"Friday", "Saturday"]

for day in days:


timetable[day] = [random.choice(subjects) for _ in
range(target_class["periods"])]

target_class["timetable"] = timetable
print("Timetable generated successfully.")
for day, periods in timetable.items():
print(f"{day}: {', '.join(periods)}")
except ValueError:
print("Invalid input. Please try again.")

# View timetable
def view_timetable(data):
try:
class_id = int(input("Enter class: "))
section = input("Enter section: ")
target_class = next(
(c for c in data["classes"] if c["class"] == class_id and
c["section"] == section), None
)
if not target_class or "timetable" not in target_class:
print("Timetable not found.")
return

for day, periods in target_class["timetable"].items():


print(f"{day}: {', '.join(periods)}")
except ValueError:
print("Invalid input. Please try again.")

# Teacher menu
def teacher_menu(data):
while True:
print("----Teacher Menu----")
print("1. Add Teacher")
print("2. Delete Teacher")
print("3. Add Class")
print("4. Delete Class")
print("5. Generate Timetable")
print("6. Go Back")
choice = input("Enter your choice: ")

if choice == "1":
add_teacher(data)
elif choice == "2":
delete_teacher(data)
elif choice == "3":
add_class(data)
elif choice == "4":
delete_class(data)
elif choice == "5":
generate_timetable(data)
elif choice == "6":
break
else:
print("Invalid choice. Try again.")

# Student menu
def student_menu(data):
while True:
print("----Student Menu----")
print("1. View Timetable")
print("2. Go Back")
choice = input("Enter your choice: ")

if choice == "1":
view_timetable(data)
elif choice == "2":
break
else:
print("Invalid choice. Try again.")

# Main menu
def main():
data = load_data()
while True:
print("----Welcome----")
print("1. Teacher")
print("2. Student")
print("3. Exit")
choice = input("Enter your choice: ")

if choice == "1":
teacher_menu(data)
elif choice == "2":
student_menu(data)
elif choice == "3":
save_data(data)
print("Thank you for using the system!")
break
else:
print("Invalid choice. Try again.")

if __name__ == "__main__":
main()

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy