python - 我的 python 应用程序控制台锁不起作用
问题描述
我正在开发这个 python 应用程序。我希望在有参赛者进入时锁定所有其他按钮。我创建了一个变量lock = False
,但它似乎不起作用。我认为这是一个缩进问题,但我不确定并且需要一些帮助。
import pps_emu
import os
def main():
sensor = pps_emu.Sensor() # Establish connection with pps_emu sensor.
clear = lambda: os.system('cls')
contest_controls = [ # Set up explanation of the controls and the orientation to the contestants and host
['Contestant 1', 'Button_1', 'rled'],
['Contestant 2', 'Button_2', 'yled'],
['Contestant 3', 'Button_3', 'gled'],
['Game Show Host', 'Button_4', 'None']]
# Print statements for the game show instructions
print('********************************************')
print('Welcome to the Quiz Game Buzzer Application')
print('********************************************')
print()
print('This program allows contestants to buzz in to answer questions for the')
print('Are you smarter than Mr. Sciallo game. It will print status messages to the screen.')
print('We will use the following button and light assignment.')
print()
print('Contestant/Host: \t Button: \t LED:')
print('********************************************')
for i in contest_controls:
print(
'{:<15}\t: {:>}\t {:<}'.format(i[0], i[1], i[2])) # Prints contestant controls with the instructions
print()
print('Press buzzer to answer question')
lock = False
while True: # start the forever loop
contestant = 0 # initialize the contestant variable
if sensor.input('Button_1') == 'pressed': # Contestant 1 button set up
if lock:
print('Another contestant is already buzzed in')
else:
lock = True
sensor.output('rled', 'on')
sensor.output('buzz', 'on')
print('Contestant 1 is buzzed in!')
if sensor.input('Button_2') == 'pressed': # Contestant 2 button set up
if lock:
print('Another contestant is already buzzed in')
else:
lock = True
sensor.output('yled', 'on')
sensor.output('buzz', 'on')
print("Contestant 2 buzzed in!")
if sensor.input('Button_3') == 'pressed': # Contestant 3 button set up
if lock:
print('Another contestant is already buzzed in')
else:
lock = True
sensor.output('gled', 'on')
sensor.output('buzz', 'on')
print("Contestant 3 buzzed in!")
if sensor.input('Button_4') == 'pressed': # Host button set up
sensor.output('rled', 'off')
sensor.output('yled', 'off')
sensor.output('gled', 'off')
if sensor.input('light') == 'on': # Quit if user turn on the light sensor
print("Quitting") # print quitting
clear()
quit()
break # break the loop
host = 0 # initialize the host variable
while host == "Button_4": # start other loop
if sensor.input('Button_4') == 'pressed': # Host button set up
print("Host Pressed") # print host pressed
sensor.output('rled', 'off')
sensor.output('yled', 'off')
sensor.output('gled', 'off')
if __name__ == "__main__": # Tell the Python interpreter to execute this main()
main()
解决方案
推荐阅读
- c# - 如何创建自定义 Active Directory 权限和组,以便我可以针对此验证用户?
- f# - 在 F# 的编译时获取模块的类型
- git - 按分支拆分提交历史
- r - 将数据(已经在多个数据帧中)重组为 R 中不同的多个数据帧
- swift - 子 uiviewcontroller 未加载到导航栏上
- python - AttributeError:“列表”对象没有属性“tk”
- java - 如何在 Collection 中处理返回类型中的泛型类型
- java - 使用 WebServiceTemplate 设置自定义标头
- c - 使用 gcc 编译时关闭程序
- regex - SublimeText:如何使用正则表达式在字符串中查找动态内容?