2017-09-13 124 views
-2

我遇到了语法和条件语法问题。我正在尝试编写一个函数,该函数返回设置闹钟的时间,具体取决于两个参数,它是哪一天以及该人是否在度假。我的日子编码为0 =星期日,1 =星期一...... 6 =星期六。该功能需要返回'7:00平日而不是休假,'10:00'平日假期和周末不休假,最后在周末不返还假期返回'off'。到目前为止,我有以下代码,但我在Wing中得到一个语法错误,无法弄清楚我的问题是什么。任何帮助表示赞赏。Python条件和If语句语法

def alarm_clock(day, on_vacation): 
    """Alarm clock function""" 

    if (int(day) < 6 and int(day) != 0) and not on_vacation: 
     return('7:00') 

    elif (int(day) = 6 or int(day) = 0) and not on_vacation: 
     return('10:00') 

    elif (int(day) < 6 or int(day) != 0) and on_vacation: 
     return('10:00') 

    elif (int(day) = 6 or int(day) = 0) and on_vacation: 
     return('off') 
+3

等于运算符是''==,而不是'='。 – Kevin

回答

0

那是因为你正在使用=代替==的比较。

喜欢在int(day) = 6。它应该是:

int(day) == 6 
+0

哦,哇,非常感谢! –

1

您试图使用=(赋值运算符)来比较值。您应该改用==

实施例:电流:int(day) = 6,正确的:int(day) == 6