Untitled

mail@pastecode.io avatar
unknown
plain_text
7 months ago
1.4 kB
2
Indexable
Never
import pandas as pd
import random

subjects = ["Physics", "Maths", "Chemistry", "Biology", "Computer", "Games"]
day_mapping = {
    1: "Monday",
    2: "Tuesday",
    3: "Wednesday",
    4: "Thursday",
    5: "Friday"
}
class_timings = [
    "08:00 AM - 09:00 AM", "09:00 AM - 10:00 AM", "10:00 AM - 10:30 AM",
    "10:30 AM - 11:30 AM", "11:30 AM - 12:30 PM", "12:30 PM - 01:00 PM",
    "01:00 PM - 02:00 PM", "02:00 PM - 03:00 PM"
]
timetable = pd.DataFrame(columns=["Day"] + subjects)

for day_number in range(1, 6):
    day_name = day_mapping[day_number]
    day_subjects = subjects.copy()
    random.shuffle(day_subjects)

    # Initialize a row for the day with the day name
    day_row = [day_name] + [""] * len(subjects)

    # Fill in the subjects and breaks in the row
    for i, timing in enumerate(class_timings):
        if i % 8 == 0 or i % 8 == 1:
            # Set the first two timing slots to subjects
            subject = day_subjects.pop(0)
        elif i % 8 == 2 or i % 8 == 5:
            subject = "Break"
        else:
            subject = day_subjects.pop(0)
        if i < 5:
            day_row[i + 1] = subject  # +1 to account for the "Day" column

    timetable = pd.concat([timetable, pd.DataFrame([day_row], columns=timetable.columns)], ignore_index=True)

timetable.set_index("Day", inplace=True)
print(timetable)