2
\$\begingroup\$

i'm trying to make a French timetable in Python, but there's too many if and elif.

class Teacher:

    def __init__(self, name, room):
        self.room = room
        self.name = nam

    def __str__(self):
        return '{}: {}'.format(self.name, self.room)

class Day:

    def __init__(self, name, week, lessons):
        self.name = name
        self.week = week
        self.lessons = lessons

    def __str__(self):
        return '{} {}\n{}'.format(
            self.name,
            self.week,
            '\n'.join(' {!s}'.format(x) for x in self.lessons)


a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p = "rien", "rien","rien", "rien", "rien", "rien", "rien", "rien","rien", "rien", "rien", "rien", "rien", "rien","rien", "rien"

prog = input("Bonjour! Voulez-vous programmer une matiere dans  la semaine? (o/n):").lower()

while prog == "o": 

    print("1-Dessin, 2-English, 3-Maths, 4-Info, 5-Electronique, 6-Biochimie:\nChoisissez le chiffre de la matiere a programmer")

    x = input()

    print("1-Lundi, 2-Mardi, 3-Mercredi, 4-Jeudi, 5-Vendredi, 6-Samedi:\nChoisissez le chiffre du jour")

    y = input()

    print("1- A |8H-11H|, 2- A |11H-13H| , 3- A |14H-17H| :\nA quel heure?")

    z = input()

    if (
            x == '1' and y == '1' and z == '1'
        ):
            if ( 
                    a == "rien" 
                ):
                    a=E1
            elif ( 
                    a != "rien" 
                ):
                    print("!!!!!!DESOLE la session est deja occupee!!!!!! ")
    elif (
            x == '1' and y == '1' and z == '2'
        ):
            if ( 
                    b == "rien" 
                ):
                    b=E1
            elif ( 
                    b != "rien" 
                ):
                    print("!!!!!!DESOLE la session est deja occupee!!!!!! ")
    elif (
            x == '1' and y == '1' and z == '3'
        ):
            if ( 
                    c == "rien" 
                ):
                    c=E1
            elif ( 
                    c != "rien" 
                ):
                    print("!!!!!!DESOLE la session est deja occupee!!!!!! ")
    elif (
            x == '1' and y == '2' and z == '1'
        ):
            if ( 
                    d == "rien" 
                ):
                    d=E1
            elif ( 
                    d != "rien" 
                ):
                    print("!!!DESOLE la session est deja occupee!!! ")
    elif (
            x == '1' and y == '2' and z == '2'
        ):
            if ( 
                    e == "rien" 
                ):
                    e=E1
            elif ( 
                    e != "rien" 
                ):
                    print("!!!DESOLE la session est deja occupee!!! ")
    elif (
            x == '1' and y == '2' and z == '3'
        ):
            if ( 
                    f == "rien" 
                ):
                    f=E1
            elif ( 
                    f != "rien" 
                ):
                    print("!!!DESOLE la session est deja occupee!!! ")
    elif (
            x == '1' and y == '3' and z == '1'
        ):
            if ( 
                    g == "rien" 
                ):
                    g=E1
            elif ( 
                    g != "rien" 
                ):
                    print("!!!DESOLE la session est deja occupee!!! ")
    elif (
            x == '1' and y == '3' and z == '2'
        ):
            if ( 
                    h == "rien" 
                ):
                    h=E1
            elif ( 
                    h != "rien" 
                ):
                    print("!!!DESOLE la session est deja occupee!!! ")
    elif (
            x == '1' and y == '3' and z == '3'
        ):
                    print("!!!DESOLE les cours s'arretent a midi le mercredi!!! ")
    elif (
            x == '1' and y == '4' and z == '1'
        ):
            if ( 
                    i == "rien" 
                ):
                    i=E1
            elif ( 
                    i != "rien" 
                ):
                    print("!!!DESOLE la session est deja occupee!!! ")
    elif (
            x == '1' and y == '4' and z == '2'
        ):
            if ( 
                    j == "rien" 
                ):
                    j=E1
            elif ( 
                    j != "rien" 
                ):
                    print("!!!DESOLE la session est deja occupee!!! ")
    elif (
            x == '1' and y == '4' and z == '3'
        ):
            if ( 
                    k == "rien" 
                ):
                    k=E1
            elif ( 
                    k != "rien" 
                ):
                    print("!!!DESOLE la session est deja occupee!!! ")
    elif (
            x == '1' and y == '5' and z == '1'
        ):
            if ( 
                    l == "rien" 
                ):
                    l=E1
            elif ( 
                    l != "rien" 
                ):
                    print("!!!DESOLE la session est deja occupee!!! ")
    elif (
            x == '1' and y == '5' and z == '2'
        ):
            if ( 
                    m == "rien" 
                ):
                    m=E1
            elif ( 
                    m != "rien" 
                ):
                    print("!!!DESOLE la session est deja occupee!!! ")
    elif (
            x == '1' and y == '5' and z == '3'
        ):
            if ( 
                    n == "rien" 
                ):
                    n=E1
            elif ( 
                    n != "rien" 
                ):
                    print("!!!DESOLE la session est deja occupee!!! ")
    elif (
            x == '1' and y == '6' and z == '1'
        ):
            if ( 
                    o == "rien" 
                ):
                    o=E1
            elif ( 
                    o != "rien" 
                ):
                    print("!!!DESOLE la session est deja occupee!!! ")
    elif (
            x == '1' and y == '6' and z == '2'
        ):
            if ( 
                    p == "rien" 
                ):
                    p=E1
            elif ( 
                    p != "rien" 
                ):
                    print("!!!DESOLE la session est deja occupee!!! ")
    elif (
            x == '1' and y == '6' and z == '3'
        ):
                    print("!!!DESOLE les cours s'arretent a midi le samedi ")
    if (
            x == '2' and y == '1' and z == '1'
        ):
            if ( 
                    a == "rien" 
                ):
                    a=E2
            elif ( 
                    a != "rien" 
                ):
                    print("!!!DESOLE la session est deja occupee!!! ")
    elif (
            x == '2' and y == '1' and z == '2'
        ):
            if ( 
                    b == "rien" 
                ):
                    b=E2
            elif ( 
                    b != "rien" 
                ):
                    print("!!!DESOLE la session est deja occupee!!! ")
    elif (
            x == '2' and y == '1' and z == '3'
        ):
            if ( 
                    c == "rien" 
                ):
                    c=E2
            elif ( 
                    c != "rien" 
                ):
                    print("!!!DESOLE la session est deja occupee!!! ")
    elif (
            x == '2' and y == '2' and z == '1'
        ):
            if ( 
                    d == "rien" 
                ):
                    d=E2
            elif ( 
                    d != "rien" 
                ):
                    print("!!!DESOLE la session est deja occupee!!! ")
    elif (
            x == '2' and y == '2' and z == '2'
        ):
            if ( 
                    e == "rien" 
                ):
                    e=E2
            elif ( 
                    e != "rien" 
                ):
                    print("!!!DESOLE la session est deja occupee!!! ")
    elif (
            x == '2' and y == '2' and z == '3'
        ):
            if ( 
                    f == "rien" 
                ):
                    f=E2
            elif ( 
                    f != "rien" 
                ):
                    print("!!!DESOLE la session est deja occupee!!! ")
    elif (
            x == '2' and y == '3' and z == '1'
        ):
            if ( 
                    g == "rien" 
                ):
                    g=E2
            elif ( 
                    g != "rien" 
                ):
                    print("!!!DESOLE la session est deja occupee!!! ")
    elif (
            x == '2' and y == '3' and z == '2'
        ):
            if ( 
                    h == "rien" 
                ):
                    h=E2
            elif ( 
                    h != "rien" 
                ):
                    print("!!!DESOLE la session est deja occupee!!! ")
    elif (
            x == '2' and y == '3' and z == '3'
        ):
                    print("!!!DESOLE les cours s'arretent a midi le mercredi ")
    elif (
            x == '2' and y == '4' and z == '1'
        ):
            if ( 
                    i == "rien" 
                ):
                    i=E2
            elif ( 
                    i != "rien" 
                ):
                    print("!!!DESOLE la session est deja occupee!!! ")
    elif (
            x == '2' and y == '4' and z == '2'
        ):
            if ( 
                    j == "rien" 
                ):
                    j=E2
            elif ( 
                    j != "rien" 
                ):
                    print("!!!DESOLE la session est deja occupee!!! ")
    elif (
            x == '2' and y == '4' and z == '3'
        ):
            if ( 
                    k == "rien" 
                ):
                    k=E2
            elif ( 
                    k != "rien" 
                ):
                    print("!!!DESOLE la session est deja occupee!!! ")
    elif (
            x == '2' and y == '5' and z == '1'
        ):
            if ( 
                    l == "rien" 
                ):
                    l=E2
            elif ( 
                    l != "rien" 
                ):
                    print("!!!DESOLE la session est deja occupee!!! ")
    elif (
            x == '2' and y == '5' and z == '2'
        ):
            if ( 
                    m == "rien" 
                ):
                    m=E2
            elif ( 
                    m != "rien" 
                ):
                    print("!!!DESOLE la session est deja occupee!!! ")
    elif (
            x == '2' and y == '5' and z == '3'
        ):
            if ( 
                    n == "rien" 
                ):
                    n=E2
            elif ( 
                    n != "rien" 
                ):
                    print("!!!DESOLE la session est deja occupee!!! ")
    elif (
            x == '2' and y == '6' and z == '1'
        ):
            if ( 
                    o == "rien" 
                ):
                    o=E2
            elif ( 
                    o != "rien" 
                ):
                    print("!!!DESOLE la session est deja occupee!!! ")
    elif (
            x == '2' and y == '6' and z == '2'
        ):
            if ( 
                    p == "rien" 
                ):
                    p=E2
            elif ( 
                    p != "rien" 
                ):
                    print("!!!DESOLE la session est deja occupee!!! ")
    elif (
            x == '2' and y == '6' and z == '3'
        ):
                    print("!!!DESOLE les cours s'arretent a midi le samedi ")
    if (
            x == '3' and y == '1' and z == '1'
        ):
            if ( 
                    a == "rien" 
                ):
                    a=E3
            elif ( 
                    a != "rien" 
                ):
                    print("!!!DESOLE la session est deja occupee!!! ")
    elif (
            x == '3' and y == '1' and z == '2'
        ):
            if ( 
                    b == "rien" 
                ):
                    b=E3
            elif ( 
                    b != "rien" 
                ):
                    print("!!!DESOLE la session est deja occupee!!! ")
    elif (
            x == '3' and y == '1' and z == '3'
        ):
            if ( 
                    c == "rien" 
                ):
                    c=E3
            elif ( 
                    c != "rien" 
                ):
                    print("!!!DESOLE la session est deja occupee!!! ")
    elif (
            x == '3' and y == '2' and z == '1'
        ):
            if ( 
                    d == "rien" 
                ):
                    d=E3
            elif ( 
                    d != "rien" 
                ):
                    print("!!!DESOLE la session est deja occupee!!! ")
    elif (
            x == '3' and y == '2' and z == '2'
        ):
            if ( 
                    e == "rien" 
                ):
                    e=E3
            elif ( 
                    e != "rien" 
                ):
                    print("!!!DESOLE la session est deja occupee!!! ")
    elif (
            x == '3' and y == '2' and z == '3'
        ):
            if ( 
                    f == "rien" 
                ):
                    f=E3
            elif ( 
                    f != "rien" 
                ):
                    print("!!!DESOLE la session est deja occupee!!! ")
    elif (
            x == '3' and y == '3' and z == '1'
        ):
            if ( 
                    g == "rien" 
                ):
                    g=E3
            elif ( 
                    g != "rien" 
                ):
                    print("!!!DESOLE la session est deja occupee!!! ")
    elif (
            x == '3' and y == '3' and z == '2'
        ):
            if ( 
                    h == "rien" 
                ):
                    h=E3
            elif ( 
                    h != "rien" 
                ):
                    print("!!!DESOLE la session est deja occupee!!! ")
    elif (
            x == '3' and y == '3' and z == '3'
        ):
                    print("!!!DESOLE les cours s'arretent a midi le mercredi ")
    elif (
            x == '3' and y == '4' and z == '1'
        ):
            if ( 
                    i == "rien" 
                ):
                    i=E3
            elif ( 
                    i != "rien" 
                ):
                    print("!!!DESOLE la session est deja occupee!!! ")
    elif (
            x == '3' and y == '4' and z == '2'
        ):
            if ( 
                    j == "rien" 
                ):
                    j=E3
            elif ( 
                    j != "rien" 
                ):
                    print("!!!DESOLE la session est deja occupee!!! ")
    elif (
            x == '3' and y == '4' and z == '3'
        ):
            if ( 
                    k == "rien" 
                ):
                    k=E3
            elif ( 
                    k != "rien" 
                ):
                    print("!!!DESOLE la session est deja occupee!!! ")
    elif (
            x == '3' and y == '5' and z == '1'
        ):
            if ( 
                    l == "rien" 
                ):
                    l=E3
            elif ( 
                    l != "rien" 
                ):
                    print("!!!DESOLE la session est deja occupee!!! ")
    elif (
            x == '3' and y == '5' and z == '2'
        ):
            if ( 
                    m == "rien" 
                ):
                    m=E3
            elif ( 
                    m != "rien" 
                ):
                    print("!!!DESOLE la session est deja occupee!!! ")
    elif (
            x == '3' and y == '5' and z == '3'
        ):
            if ( 
                    n == "rien" 
                ):
                    n=E3
            elif ( 
                    n != "rien" 
                ):
                    print("!!!DESOLE la session est deja occupee!!! ")
    elif (
            x == '3' and y == '6' and z == '1'
        ):
            if ( 
                    o == "rien" 
                ):
                    o=E3
            elif ( 
                    o != "rien" 
                ):
                    print("!!!DESOLE la session est deja occupee!!! ")
    elif (
            x == '3' and y == '6' and z == '2'
        ):
            if ( 
                    p == "rien" 
                ):
                    p=E3
            elif ( 
                    p != "rien" 
                ):
                    print("!!!DESOLE la session est deja occupee!!! ")
    elif (
            x == '3' and y == '6' and z == '3'
        ):
                    print("!!!DESOLE les cours s'arretent a midi le samedi ")
    if (
            x == '4' and y == '1' and z == '1'
        ):
            if ( 
                    a == "rien" 
                ):
                    a=E4
            elif ( 
                    a != "rien" 
                ):
                    print("!!!DESOLE la session est deja occupee!!! ")
    elif (
            x == '4' and y == '1' and z == '2'
        ):
            if ( 
                    b == "rien" 
                ):
                    b=E4
            elif ( 
                    b != "rien" 
                ):
                    print("!!!DESOLE la session est deja occupee!!! ")
    elif (
            x == '4' and y == '1' and z == '3'
        ):
            if ( 
                    c == "rien" 
                ):
                    c=E4
            elif ( 
                    c != "rien" 
                ):
                    print("!!!DESOLE la session est deja occupee!!! ")
    elif (
            x == '4' and y == '2' and z == '1'
        ):
            if ( 
                    d == "rien" 
                ):
                    d=E4
            elif ( 
                    d != "rien" 
                ):
                    print("!!!DESOLE la session est deja occupee!!! ")
    elif (
            x == '4' and y == '2' and z == '2'
        ):
            if ( 
                    e == "rien" 
                ):
                    e=E4
            elif ( 
                    e != "rien" 
                ):
                    print("!!!DESOLE la session est deja occupee!!! ")
    elif (
            x == '4' and y == '2' and z == '3'
        ):
            if ( 
                    f == "rien" 
                ):
                    f=E4
            elif ( 
                    f != "rien" 
                ):
                    print("!!!DESOLE la session est deja occupee!!! ")
    elif (
            x == '4' and y == '3' and z == '1'
        ):
            if ( 
                    g == "rien" 
                ):
                    g=E4
            elif ( 
                    g != "rien" 
                ):
                    print("!!!DESOLE la session est deja occupee!!! ")
    elif (
            x == '4' and y == '3' and z == '2'
        ):
            if ( 
                    h == "rien" 
                ):
                    h=E4
            elif ( 
                    h != "rien" 
                ):
                    print("!!!DESOLE la session est deja occupee!!! ")
    elif (
            x == '4' and y == '3' and z == '3'
        ):
                    print("!!!DESOLE les cours s'arretent a midi le mercredi ")
    elif (
            x == '4' and y == '4' and z == '1'
        ):
            if ( 
                    i == "rien" 
                ):
                    i=E4
            elif ( 
                    i != "rien" 
                ):
                    print("!!!DESOLE la session est deja occupee!!! ")
    elif (
            x == '4' and y == '4' and z == '2'
        ):
            if ( 
                    j == "rien" 
                ):
                    j=E4
            elif ( 
                    j != "rien" 
                ):
                    print("!!!DESOLE la session est deja occupee!!! ")
    elif (
            x == '4' and y == '4' and z == '3'
        ):
            if ( 
                    k == "rien" 
                ):
                    k=E4
            elif ( 
                    k != "rien" 
                ):
                    print("!!!DESOLE la session est deja occupee!!! ")
    elif (
            x == '4' and y == '5' and z == '1'
        ):
            if ( 
                    l == "rien" 
                ):
                    l=E4
            elif ( 
                    l != "rien" 
                ):
                    print("!!!DESOLE la session est deja occupee!!! ")
    elif (
            x == '4' and y == '5' and z == '2'
        ):
            if ( 
                    m == "rien" 
                ):
                    m=E4
            elif ( 
                    m != "rien" 
                ):
                    print("!!!DESOLE la session est deja occupee!!! ")
    elif (
            x == '4' and y == '5' and z == '3'
        ):
            if ( 
                    n == "rien" 
                ):
                    n=E4
            elif ( 
                    n != "rien" 
                ):
                    print("!!!DESOLE la session est deja occupee!!! ")
    elif (
            x == '4' and y == '6' and z == '1'
        ):
            if ( 
                    o == "rien" 
                ):
                    o=E4
            elif ( 
                    o != "rien" 
                ):
                    print("!!!DESOLE la session est deja occupee!!! ")
    elif (
            x == '4' and y == '6' and z == '2'
        ):
            if ( 
                    p == "rien" 
                ):
                    p=E4
            elif ( 
                    p != "rien" 
                ):
                    print("!!!DESOLE la session est deja occupee!!! ")
    elif (
            x == '4' and y == '6' and z == '3'
        ):
                    print("!!!DESOLE les cours s'arretent a midi le samedi")
    if (
            x == '5' and y == '1' and z == '1'
        ):
            if ( 
                    a == "rien" 
                ):
                    a=E5
            elif ( 
                    a != "rien" 
                ):
                    print("!!!DESOLE la session est deja occupee!!! ")
    elif (
            x == '5' and y == '1' and z == '2'
        ):
            if ( 
                    b == "rien" 
                ):
                    b=E5
            elif ( 
                    b != "rien" 
                ):
                    print("!!!DESOLE la session est deja occupee!!! ")
    elif (
            x == '5' and y == '1' and z == '3'
        ):
            if ( 
                    c == "rien" 
                ):
                    c=E5
            elif ( 
                    c != "rien" 
                ):
                    print("!!!DESOLE la session est deja occupee!!! ")
    elif (
            x == '5' and y == '2' and z == '1'
        ):
            if ( 
                    d == "rien" 
                ):
                    d=E5
            elif ( 
                    d != "rien" 
                ):
                    print("!!!DESOLE la session est deja occupee!!! ")
    elif (
            x == '5' and y == '2' and z == '2'
        ):
            if ( 
                    e == "rien" 
                ):
                    e=E5
            elif ( 
                    e != "rien" 
                ):
                    print("!!!DESOLE la session est deja occupee!!! ")
    elif (
            x == '5' and y == '2' and z == '3'
        ):
            if ( 
                    f == "rien" 
                ):
                    f=E5
            elif ( 
                    f != "rien" 
                ):
                    print("!!!DESOLE la session est deja occupee!!! ")
    elif (
            x == '5' and y == '3' and z == '1'
        ):
            if ( 
                    g == "rien" 
                ):
                    g=E5
            elif ( 
                    g != "rien" 
                ):
                    print("!!!DESOLE la session est deja occupee!!! ")
    elif (
            x == '5' and y == '3' and z == '2'
        ):
            if ( 
                    h == "rien" 
                ):
                    h=E5
            elif ( 
                    h != "rien" 
                ):
                    print("!!!DESOLE la session est deja occupee!!! ")
    elif (
            x == '5' and y == '3' and z == '3'
        ):
                    print("!!!DESOLE les cours s'arretent a midi le mercredi ")
    elif (
            x == '5' and y == '4' and z == '1'
        ):
            if ( 
                    i == "rien" 
                ):
                    i=E5
            elif ( 
                    i != "rien" 
                ):
                    print("!!!DESOLE la session est deja occupee!!! ")
    elif (
            x == '5' and y == '4' and z == '2'
        ):
            if ( 
                    j == "rien" 
                ):
                    j=E5
            elif ( 
                    j != "rien" 
                ):
                    print("!!!DESOLE la session est deja occupee!!! ")
    elif (
            x == '5' and y == '4' and z == '3'
        ):
            if ( 
                    k == "rien" 
                ):
                    k=E5
            elif ( 
                    k != "rien" 
                ):
                    print("!!!DESOLE la session est deja occupee!!! ")
    elif (
            x == '5' and y == '5' and z == '1'
        ):
            if ( 
                    l == "rien" 
                ):
                    l=E5
            elif ( 
                    l != "rien" 
                ):
                    print("!!!DESOLE la session est deja occupee!!! ")
    elif (
            x == '5' and y == '5' and z == '2'
        ):
            if ( 
                    m == "rien" 
                ):
                    m=E5
            elif ( 
                    m != "rien" 
                ):
                    print("!!!DESOLE la session est deja occupee!!! ")
    elif (
            x == '5' and y == '5' and z == '3'
        ):
            if ( 
                    n == "rien" 
                ):
                    n=E5
            elif ( 
                    n != "rien" 
                ):
                    print("!!!DESOLE la session est deja occupee!!! ")
    elif (
            x == '5' and y == '6' and z == '1'
        ):
            if ( 
                    o == "rien" 
                ):
                    o=E5
            elif ( 
                    o != "rien" 
                ):
                    print("!!!DESOLE la session est deja occupee!!! ")
    elif (
            x == '5' and y == '6' and z == '2'
        ):
            if ( 
                    p == "rien" 
                ):
                    p=E5
            elif ( 
                    p != "rien" 
                ):
                    print("!!!DESOLE la session est deja occupee!!! ")
    elif (
            x == '5' and y == '6' and z == '3'
        ):
                    print("!!!DESOLE les cours s'arretent a midi le samedi ")
    if (
            x == '6' and y == '1' and z == '1'
        ):
            if ( 
                    a == "rien" 
                ):
                    a=E6
            elif ( 
                    a != "rien" 
                ):
                    print("!!!DESOLE la session est deja occupee!!! ")
    elif (
            x == '6' and y == '1' and z == '2'
        ):
            if ( 
                    b == "rien" 
                ):
                    b=E6
            elif ( 
                    b != "rien" 
                ):
                    print("!!!DESOLE la session est deja occupee!!! ")
    elif (
            x == '6' and y == '1' and z == '3'
        ):
            if ( 
                    c == "rien" 
                ):
                    c=E6
            elif ( 
                    c != "rien" 
                ):
                    print("!!!DESOLE la session est deja occupee!!! ")
    elif (
            x == '6' and y == '2' and z == '1'
        ):
            if ( 
                    d == "rien" 
                ):
                    d=E6
            elif ( 
                    d != "rien" 
                ):
                    print("!!!DESOLE la session est deja occupee!!! ")
    elif (
            x == '6' and y == '2' and z == '2'
        ):
            if ( 
                    e == "rien" 
                ):
                    e=E6
            elif ( 
                    e != "rien" 
                ):
                    print("!!!DESOLE la session est deja occupee!!! ")
    elif (
            x == '6' and y == '2' and z == '3'
        ):
            if ( 
                    f == "rien" 
                ):
                    f=E6
            elif ( 
                    f != "rien" 
                ):
                    print("!!!DESOLE la session est deja occupee!!! ")
    elif (
            x == '6' and y == '3' and z == '1'
        ):
            if ( 
                    g == "rien" 
                ):
                    g=E6
            elif ( 
                    g != "rien" 
                ):
                    print("!!!DESOLE la session est deja occupee!!! ")
    elif (
            x == '6' and y == '3' and z == '2'
        ):
            if ( 
                    h == "rien" 
                ):
                    h=E6
            elif ( 
                    h != "rien" 
                ):
                    print("!!!DESOLE la session est deja occupee!!! ")
    elif (
            x == '6' and y == '3' and z == '3'
        ):
                    print("!!!DESOLE les cours s'arretent a midi le mercredi ")
    elif (
            x == '6' and y == '4' and z == '1'
        ):
            if ( 
                    i == "rien" 
                ):
                    i=E6
            elif ( 
                    i != "rien" 
                ):
                    print("!!!DESOLE la session est deja occupee!!! ")
    elif (
            x == '6' and y == '4' and z == '2'
        ):
            if ( 
                    j == "rien" 
                ):
                    j=E6
            elif ( 
                    j != "rien" 
                ):
                    print("!!!DESOLE la session est deja occupee!!! ")
    elif (
            x == '6' and y == '4' and z == '3'
        ):
            if ( 
                    k == "rien" 
                ):
                    k=E6
            elif ( 
                    k != "rien" 
                ):
                    print("!!!DESOLE la session est deja occupee!!! ")
    elif (
            x == '6' and y == '5' and z == '1'
        ):
            if ( 
                    l == "rien" 
                ):
                    l=E6
            elif ( 
                    l != "rien" 
                ):
                    print("!!!DESOLE la session est deja occupee!!! ")
    elif (
            x == '6' and y == '5' and z == '2'
        ):
            if ( 
                    m == "rien" 
                ):
                    m=E6
            elif ( 
                    m != "rien" 
                ):
                    print("!!!DESOLE la session est deja occupee!!! ")
    elif (
            x == '6' and y == '5' and z == '3'
        ):
            if ( 
                    n == "rien" 
                ):
                    n=E6
            elif ( 
                    n != "rien" 
                ):
                    print("!!!DESOLE la session est deja occupee!!! ")
    elif (
            x == '6' and y == '6' and z == '1'
        ):
            if ( 
                    o == "rien" 
                ):
                    o=E6
            elif ( 
                    o != "rien" 
                ):
                    print("!!!DESOLE la session est deja occupee!!! ")
    elif (
            x == '6' and y == '6' and z == '2'
        ):
            if ( 
                    p == "rien" 
                ):
                    p=E6
            elif ( 
                    p != "rien" 
                ):
                    print("!!!DESOLE la session est deja occupee!!! ")
    elif (
            x == '6' and y == '6' and z == '3'
        ):
                    print("!!!DESOLE les cours s'arretent a midi le samedi ")
    if (
            a == b and b != 'rien'
        ):
            print("La matiere programmee Lundi a franchi la limite des 3h de cours, les heures supp seront retires automatiquement")
            b = 'rien'
    if (
            a == c and c != 'rien'
        ):
            print("La matiere programmee Lundi a franchi la limite des 3h de cours, les heures supp seront retires automatiquement")
            c = 'rien'
    if (
            b == c and c != 'rien'
        ):
            print("La matiere programmee Lundi a franchi la limite des 3h de cours, les heures supp seront retires automatiquement")
            c = 'rien'
    if (
            d == e and e != 'rien'
        ):
            print("La matiere programmee Mardi a franchi la limite des 3h de cours, les heures supp seront retires automatiquement")
            e = 'rien'
    if (
            d == f and f != 'rien'
        ):
            print("La matiere programmee Mardi a franchi la limite des 3h de cours, les heures supp seront retires automatiquement")
            f = 'rien'
    if (
            e == f and f != 'rien'
        ):
            print("La matiere programmee Mardi a franchi la limite des 3h de cours, les heures supp seront retires automatiquement")
            f = 'rien'
    if (
            g == h and h != 'rien'
        ):
            print("La matiere programmee Mercredi a franchi la limite des 3h de cours, les heures supp seront retires automatiquement")
            h = 'rien'
    if (
            i == j and j != 'rien'
        ):
            print("La matiere programmee Jeudi a franchi la limite des 3h de cours, les heures supp seront retires automatiquement")
            j = 'rien'
    if (
            i == k and k != 'rien'
        ):
            print("La matiere programmee Jeudi a franchi la limite des 3h de cours, les heures supp seront retires automatiquement")
            k = 'rien'
    if (
            j == k and k != 'rien'
        ):
            print("La matiere programmee Jeudi a franchi la limite des 3h de cours, les heures supp seront retires automatiquement")
            k = 'rien'
    if (
            l == m and m != 'rien'
        ):
            print("La matiere programmee Vendredi a franchi la limite des 3h de cours, les heures supp seront retires automatiquement")
            m = 'rien'
    if (
            l == n and n != 'rien'
        ):
            print("La matiere programmee Vendredi a franchi la limite des 3h de cours, les heures supp seront retires automatiquement")
            n = 'rien'
    if (
            m == n and n != 'rien'
        ):
            print("La matiere programmee Vendredi a franchi la limite des 3h de cours, les heures supp seront retires automatiquement")
            n = 'rien'
    if (
            o == p and p != 'rien'
        ):
            print("La matiere programmee Samedi a franchi la limite des 3h de cours, les heures supp seront retires automatiquement")
            p = 'rien'
\$\endgroup\$
  • \$\begingroup\$ Welcome to CR, can you explain the logic of code in the description please? \$\endgroup\$ – 422_unprocessable_entity Feb 20 at 8:54
  • \$\begingroup\$ what are a, b etc? \$\endgroup\$ – Maarten Fabré Feb 20 at 8:57
  • 1
    \$\begingroup\$ Pleas edit the title of your question so it contains what this code achieves (a scheduling application?) and not what you want out of a review. Otherwise we would soon run out of variations of "How to make my code better" as question titles. \$\endgroup\$ – Graipher Feb 20 at 10:07
  • \$\begingroup\$ what does a=E4 do \$\endgroup\$ – Maarten Fabré Feb 20 at 10:18
  • \$\begingroup\$ E1, E2...E6 are courses that are not variables...a,b,c.... Are the actual House for each course in the timetable e.g monday we have 3 courses so 'a" is the firste one, b the second and c the third, tuesday we also have 3 courses so "d", "e" and "f" are their courses and so on, also they are all set to "rien" which means "nothing" at the beginning and compare ony by one...every day has 3 courses except wednesday and saturday that only got 2 \$\endgroup\$ – Black Atis Feb 20 at 16:00
4
\$\begingroup\$

Enums

You have a definite number of courses, weekdays and timeslots. So instead of using numbers to represent them, you can better use Enums

from enum import Enum
class Courses(Enum):
    Dessin = 1
    English = 2
    Maths = 3
    Info = 4
    Electronique = 5
    Biochimie = 6

class Timeslots(Enum):
    morning = "|8H-11H|"
    noon = "|11H-13H|"
    afternoon = "|14H-17H|"

class Weekdays(Enum):
    Lundi = 1
    Mardi = 2
    Mercredi = 3
    Jeudi = 4
    Vendredi = 5
    Samedi = 6

"rien"

You use "rien" as a sentinel value. A better way to express this would be to use None

input

There is a lot of reused code to get the input, and no validation. Better would be to use a separate function to gather the input

def get_input(inputs, message=""):
    while True:
        try:
            msg = ", ".join(f"{value.value}-{value.name}" for value in inputs)
            msg += message
            value= input(msg)
            if value.isdigit():
                return inputs(int(value))
            return inputs[value]
        except (KeyError, ValueError):
            pass

This can be used as:

course = get_input(Courses, """
Choisissez le chiffre de la matiere a programmer
""")
day = get_input(Weekdays, """
Choisissez le chiffre du jour
""")
timeslot = get_input(Timeslots, """
Choisissez la heure
""")

The last one might need a slightly different approach

if-elif

Then at least the long if-elif-else would be clear:

if (course = Courses.Dessin and day = Weekdays.Lundi and timeslot = Timeslots.morning):
...

instead of

if x == "1" and y == "1" and z == "1":

dict

Even better would be to use a datastructure to capture the schedule, instead of variables a to p. You can easily create a dict of class times:

from itertools import product
schedule= {
    day: {
        time: None
        for time in Timeslots
        if not (
            day in {Weekdays.Mercredi, Weekdays.Samedi}
            and time == Timeslots.afternoon
        )
    }
    for day in Weekdays
}

This results in:

{<Weekdays.Lundi: 1>: {<Timeslots.morning: '|8H-11H|'>: None,
  <Timeslots.noon: '|11H-13H|'>: None,
  <Timeslots.afternoon: '|14H-17H|'>: None},
 <Weekdays.Mardi: 2>: {<Timeslots.morning: '|8H-11H|'>: None,
  <Timeslots.noon: '|11H-13H|'>: None,
  <Timeslots.afternoon: '|14H-17H|'>: None},
 <Weekdays.Mercredi: 3>: {<Timeslots.morning: '|8H-11H|'>: None,
  <Timeslots.noon: '|11H-13H|'>: None},
 <Weekdays.Jeudi: 4>: {<Timeslots.morning: '|8H-11H|'>: None,
  <Timeslots.noon: '|11H-13H|'>: None,
  <Timeslots.afternoon: '|14H-17H|'>: None},
 <Weekdays.Vendredi: 5>: {<Timeslots.morning: '|8H-11H|'>: None,
  <Timeslots.noon: '|11H-13H|'>: None,
  <Timeslots.afternoon: '|14H-17H|'>: None},
 <Weekdays.Samedi: 6>: {<Timeslots.morning: '|8H-11H|'>: None,
  <Timeslots.noon: '|11H-13H|'>: None}}

Now to check whether a slot has been taken already, instead of the long if-elif-else, you get

if schedule[day][timeslot] is not None:
    print("!!!!!!DESOLE la session est deja occupee!!!!!! ")

and program a class with

else:
    schedule[day][timeslot] = course

Now to tackle the fact that on Saturday there is only one slot, you can precede this with:

if time not in schedule[day]:
    print("!!!DESOLE les cours s'arretent a midi le mercredi et samedi")

Even better would be to abstract this in a different functions, but I suggest you already try to incorporate these tips, and then see how far you get, and open a next question if you need more help.

Some future way forwards:

  • return values instead of printing messages
  • externalize the checks whether a certain course can be taken at a certain time
  • use Exceptions to communicate failures, instead of print messages
  • To tackle the choice of not allowing the same course on one day, you can implement a small validator
  • Abstract the schedule to a Class instead of a dict
\$\endgroup\$
  • \$\begingroup\$ Hello, thank you for your reoly, it helped me alot, altough i have an error somehow it says "name day is not defined" on {if schedule[day][timeslot] not NONE}...and also i dont know how to print each days with its respectives courses and hours \$\endgroup\$ – Black Atis Feb 20 at 15:50
3
\$\begingroup\$

You should think about the whole code if it is not possible to create a completely different way. I do not really know what the meaning of this code is.

But you could simplify your code:

if (
            x == '1' and y == '1' and z == '1'
        ):
            if ( 
                    a == "rien" 
                ):
                    a=E1
            elif ( 
                    a != "rien" 
                ):
                    print("!!!!!!DESOLE la session est deja occupee!!!!!! ")
 elif (...)

using this:

result = x+y+z

if result == '111' and a =='rien':
    a = E1
elif result == '112' and b == 'rien':
    b = E1
elif ...

else:
        print("!!!!!!DESOLE la session est deja occupee!!!!!! ")
\$\endgroup\$
  • \$\begingroup\$ Hey, this is smart...thx bro \$\endgroup\$ – Black Atis Feb 20 at 15:53
2
\$\begingroup\$

What about this:

timetable = [[None]*3 for _ in range(6)]

while True:
    cours = input("0-Dessin, 1-English, 2-Maths, 3-Info, 4-Electronique, 5-Biochimie:\nChoisissez le chiffre de la matiere a programmer\n")
    if cours == '': break
    jour = input("0-Lundi, 1-Mardi, 2-Mercredi, 3-Jeudi, 4-Vendredi, 5-Samedi:\nChoisissez le chiffre du jour\n")
    heure = input("0- A |8H-11H|, 1- A |11H-13H| , 2- A |14H-17H| :\nA quel heure?")
    jour, heure, cours = (int(i) for i in (jour, heure, cours))
    if timetable[jour][heure] is not None:
        timetable[jour][heure] = cours

It creates an array you can access with timetable[jour][heure] to get the course at that particular time.

\$\endgroup\$
  • \$\begingroup\$ Impressive...will look at it \$\endgroup\$ – Black Atis Feb 20 at 15:51
  • \$\begingroup\$ hen i tried i have error "list indices must be integer or slices, not str" \$\endgroup\$ – Black Atis Feb 20 at 16:37
  • \$\begingroup\$ Right, your input must be converted to int, I edited my answer. \$\endgroup\$ – Benoît Pilatte Feb 20 at 16:42
  • \$\begingroup\$ Thank u, now it says that list index out of range when i tried different number (3-3-3) \$\endgroup\$ – Black Atis Feb 20 at 18:02
  • \$\begingroup\$ Note that the number in my example start at zero, if you wish to change that. Then change (int(i) for i in (jour, heure, cours)) to (int(i) - 1 for i in (jour, heure, cours)). (Dessin is 0) \$\endgroup\$ – Benoît Pilatte Feb 20 at 18:10
1
\$\begingroup\$

First thing you should consider is creating a function with the parameters x,y,z in it that return the result.

Premièrement tu devrais créer une fonction qui a comme paramatres x,y,z et return le resultat

like so:

def function_name(x,y,z):
    if (
            x == '1' and y == '1' and z == '1'
        ):
...
return result

and use dictonaries learn about dictonaries here: https://www.tutorialspoint.com/python/python_dictionary.htm

\$\endgroup\$
  • \$\begingroup\$ Mercii, thank u will try and let you know \$\endgroup\$ – Black Atis Feb 20 at 15:51

Your Answer

By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.