Python 在 if 语句中检测到语法错误
Python Syntax errors detected on an if statement
我正在尝试 运行 我的代码,但我已经因为语法错误被困了几个小时。我尝试了不同的 if 语句级别、重写部分等……没有任何改变。有人知道吗?谢谢
我也用过在线黑客,但没有结果。
我 运行 使用 Python 3 的代码,不能 运行 使用旧版本。
错误发生在这部分代码的所有行上:
if alarmdown == 1:
bright = bright - 1
pixels.fill((brightmaxred, 0, bright)
if bright == 10:
alarmdown = 0
elif alarmdown == 0:
bright = bright + 1
pixels.fill((brightmaxred, 0, bright)
if bright == brightmaxblue:
alarmdown = 1
这是完整的代码,它是一个 RGB 条形定时器
import time
import board
import neopixel
pixels = neopixel.NeoPixel(board.D18, 24)
#variables
terminate = 0
startup = 1
bright = 1
selectpix = 0
goblue = 0
pixelstart = (0, 0, 100)
order = 1
timerexpired = 0
alarmdown = 1
brightmaxblue = 20
brightmaxred = 30
currentlow = 0
currenthigh = 23
#set timer speed
totaltime = 15 #how many seconds? approximation
timetotal = totaltime / (brightmaxred * 30)
#set a clean board
pixels.fill((0, 0, 0))
#if til true
while terminate == 0:
if startup == 1:
goblue = goblue + 1
pixels.fill((0, 0, goblue))
time.sleep(timetotal)
if goblue == brightmaxblue:
startup = 0
timer = 1
elif startup == 0:
#start from the pixel no. 0 - 23 - 1 - 22 - ...
while timer == 1:
pixels[selectpix] = (bright, 0, brightmaxblue)
bright = bright + 1
time.sleep(timetotal)
if bright == brightmaxred:
if currentlow == 12:
timer = 0
timerexpired = 1
elif selectpix == currentlow:
selectpix = currenthigh
currentlow = currentlow + 1
elif selectpix == currenthigh:
selectpix = currentlow
currenthigh = currenthigh - 1
bright = 0
if timerexpired == 1:
if alarmdown == 1:
bright = bright - 1
pixels.fill((brightmaxred, 0, bright)
if bright == 10:
alarmdown = 0
elif alarmdown == 0:
bright = bright + 1
pixels.fill((brightmaxred, 0, bright)
if bright == brightmaxblue:
alarmdown = 1
pixels.fill((brightmaxred, 0, bright)
你有两个左括号,只有一个右括号。
我正在尝试 运行 我的代码,但我已经因为语法错误被困了几个小时。我尝试了不同的 if 语句级别、重写部分等……没有任何改变。有人知道吗?谢谢
我也用过在线黑客,但没有结果。 我 运行 使用 Python 3 的代码,不能 运行 使用旧版本。
错误发生在这部分代码的所有行上:
if alarmdown == 1:
bright = bright - 1
pixels.fill((brightmaxred, 0, bright)
if bright == 10:
alarmdown = 0
elif alarmdown == 0:
bright = bright + 1
pixels.fill((brightmaxred, 0, bright)
if bright == brightmaxblue:
alarmdown = 1
这是完整的代码,它是一个 RGB 条形定时器
import time
import board
import neopixel
pixels = neopixel.NeoPixel(board.D18, 24)
#variables
terminate = 0
startup = 1
bright = 1
selectpix = 0
goblue = 0
pixelstart = (0, 0, 100)
order = 1
timerexpired = 0
alarmdown = 1
brightmaxblue = 20
brightmaxred = 30
currentlow = 0
currenthigh = 23
#set timer speed
totaltime = 15 #how many seconds? approximation
timetotal = totaltime / (brightmaxred * 30)
#set a clean board
pixels.fill((0, 0, 0))
#if til true
while terminate == 0:
if startup == 1:
goblue = goblue + 1
pixels.fill((0, 0, goblue))
time.sleep(timetotal)
if goblue == brightmaxblue:
startup = 0
timer = 1
elif startup == 0:
#start from the pixel no. 0 - 23 - 1 - 22 - ...
while timer == 1:
pixels[selectpix] = (bright, 0, brightmaxblue)
bright = bright + 1
time.sleep(timetotal)
if bright == brightmaxred:
if currentlow == 12:
timer = 0
timerexpired = 1
elif selectpix == currentlow:
selectpix = currenthigh
currentlow = currentlow + 1
elif selectpix == currenthigh:
selectpix = currentlow
currenthigh = currenthigh - 1
bright = 0
if timerexpired == 1:
if alarmdown == 1:
bright = bright - 1
pixels.fill((brightmaxred, 0, bright)
if bright == 10:
alarmdown = 0
elif alarmdown == 0:
bright = bright + 1
pixels.fill((brightmaxred, 0, bright)
if bright == brightmaxblue:
alarmdown = 1
pixels.fill((brightmaxred, 0, bright)
你有两个左括号,只有一个右括号。