jeudi 12 août 2021

How do if/elif/else statements work, mine doesn't run

months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]

for x in months:

if x == "January":
    D = 1
    M = 11
    C = 20
    Y = 20
    month_1d_January = np.zeros([42], dtype=int)
    w0_January = np.zeros([42], dtype=int)
    n = 0
    while (D <= 31):
        
        W_January = (D + (2.6*M - 0.2) - 2*C + Y + (Y/4) + (C/4)) % 7
        
        w_January = math.floor(W_January)
        w0_January[n] = w_January

        month_1d_January[w0_January[0]] = D
        if w_January == 2:
            day = "Sunday"
        elif w_January == 3:
            day = "Monday"
        elif w_January == 4:
            day = "Tuesday"
        elif w_January == 5:
            day = "Wednesday"
        elif w_January == 6:
            day = "Thursday"
        elif w_January == 0:
            day = "Friday"
        elif w_January == 1:
            day = "Saturday"

        D = D + 1
        n = n + 1
        w0_January[0] = w0_January[0] + 1

month_January_pre = np.reshape(month_1d_January,(6,7)) 
month_January = np.roll(month_January_pre,-2)       


elif x == "February":
    D = 1
    M = 12
    C = 20
    Y = 20
    month_1d_February = np.zeros([42], dtype=int)
    w0_February = np.zeros([42], dtype=int)
    n = 0
    while (D <= 28):
        
        W_February = (D + (2.6*M - 0.2) - 2*C + Y + (Y/4) + (C/4)) % 7
        
        w_February = math.floor(W_February)
        w0_February[n] = w_February

        month_1d_February[w0_February[0]] = D
        if w_February == 2:
            day = "Sunday"
        elif w_February == 3:
            day = "Monday"
        elif w_February == 4:
            day = "Tuesday"
        elif w_February == 5:
            day = "Wednesday"
        elif w_February == 6:
            day = "Thursday"
        elif w_February == 0:
            day = "Friday"
        elif w_February == 1:
            day = "Saturday"

        D = D + 1
        n = n + 1
        w0_February[0] = w0_February[0] + 1

month_February_pre = np.reshape(month_1d_February,(6,7)) 
month_February = np.roll(month_February_pre,5)       

This is in VSCode in Python 3.9.1. My error is for the elif x == "February", it says Expected expression pylance. There is more code after that I can post if needed, but it is pretty much the same. I think the part that is broke is the elif statement because that is what has an error, but it could be the while loop or the if statement inside the while loop. I'm used to MatLab where there is an end line for each loop/statement which helps me alot.

Aucun commentaire:

Enregistrer un commentaire