简体   繁体   English

代码不起作用,(DHT11 数据到 LCD)(Micro:bit)(错误:第 3 行语法错误无法分配给表达式)

[英]Code is not working, (DHT11 Data to LCD) (Micro:bit) (ERROR: line 3 syntax error can't assign to expression)

This code will not cunction for aome reason and displays (ERROR: line 3 syntax error can't assign to expression由于某种原因,此代码不会停止并显示(错误:第 3 行语法错误无法分配给表达式

#
from I2C_LCD1602_Class import I2C_LCD1602
LCD1620[0] = I2C_LCD1602_Class(0x27)
while True:
    lcd.puts("temperature:"+str(temperature()), 0, 0)
    lcd.puts("humidity:"+str(humidity()), 2, 0)

    if __name__ == '__main__':
        sensor = DHT11(pin0)
        while True:
            try:
                temperature, humidity = sensor.read()
                print("temperature:"+str(temperature)+" C")
                print("humidity:"+str(humidity)+"%")
            except Exception as e:
                print("Error : " + str(e))
        time.sleep(1)

Your first while loop ends with a "greater than" symbol instead of a colon.您的第一个 while 循环以“大于”符号而不是冒号结束。 Change while True> to while True:while True>更改为while True:

You've got你有

LCD1620(0) = I2C_LCD1602_Class(0x27)

in line three where you first make a function call, and then try to assign a value to that function call.在第三行中,您首先进行 function 调用,然后尝试为该 function 调用分配一个值。 You can't do this.你不能这样做。 Maybe you meant也许你的意思是

LCD1620[0] = I2C_LCD1602_Class(0x27)

edit: btw you've also got syntax errors on line four (as mentioned in another answer) and line 6编辑:顺便说一句,您在第 4 行(如另一个答案中提到的)和第 6 行也有语法错误

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM