-6
我想用某種循環縮短這段代碼:for,if(inside if),while,foreach,or other one。我該如何縮短這個python代碼
def FindChannel():
rc_program_up = "Ch+"
rc_ok = "ok"
rc_exit = "exit"
value0 = checkPicture(15)
if (value0 == 100):
send_rckey(rc_exit)
else:
send_rckey(rc_program_up)
value0 = checkPicture(15)
if (value0 == 100):
send_rckey(rc_exit)
else:
send_rckey(rc_program_up)
value0 = checkPicture(15)
if (value0 == 100):
send_rckey(rc_exit)
else:
send_rckey(rc_program_up)
value0 = checkPicture(15)
if (value0 == 100):
send_rckey(rc_exit)
else:
send_rckey(rc_program_up)
value0 = checkPicture(15)
if (value0 == 100):
send_rckey(rc_exit)
else:
send_rckey(rc_program_up)
value0 = checkPicture(15)
我不能這樣做,請幫助我。
修復縮進,請 – n4nn31355
你只是重複相同的5行代碼5次? – khelwood
你可以嘗試使用'elif'。 https://docs.python.org/2/tutorial/controlflow.html#if-statements –