Python 如何避免函数getch()出现问题
我的程序有问题。这是一种循环菜单。我用VS代码写。问题是,当我运行程序并尝试从它运行的三个选项中选择一个选项时,后面的选项是:打印(“无更多选项”)。代码如下:Python 如何避免函数getch()出现问题,python,getch,Python,Getch,我的程序有问题。这是一种循环菜单。我用VS代码写。问题是,当我运行程序并尝试从它运行的三个选项中选择一个选项时,后面的选项是:打印(“无更多选项”)。代码如下: from getch import getch def func_1(): print("Hello") def name(): name = input("What is your name?: ") print("Your name is: "+na
from getch import getch
def func_1():
print("Hello")
def name():
name = input("What is your name?: ")
print("Your name is: "+name)
def do_sth(a=3):
return 2 * a
while True:
print("1) Wyświetl wynik funkcji")
print("2) Wyświetl imię")
print("3) Wyświetl do Sth")
keyPressed=getch()
if keyPressed =='1':
func_1()
elif keyPressed == '2':
name()
elif keyPressed =='3':
print(do_sth())
press = input("Press any key to continue....")
else:
print("No more option")
但是,当我在Pydroid 3中的Android smatphone上编写相同的代码时,它可以很好地运行每一个函数。我不知道这是为什么?我还在PyCharm社区中编写了上面的代码,它不读取任何密钥。但在我的android smatphone上的Pydroid 3中,代码工作得非常完美。问题在于比较bytestring和字符串 尝试:
虽然我看到不同的帖子在我的vs代码中不起作用,但我在你的代码中没有看到一个
print('Error')
。好了,在keypressed=getch()
之后,没有更多的选择了:print([%s]%keypressed)
并发布你得到的内容。尝试在“1”中添加一个b。。i、 e.如果按下==b“1”:
并用2和3重复该操作
from getch import getch
def func_1():
print("Hello")
def name():
name = input("What is your name?: ")
print("Your name is: "+name)
def do_sth(a=3):
return 2 * a
while True:
print("1) Wyświetl wynik funkcji")
print("2) Wyświetl imię")
print("3) Wyświetl do Sth")
keyPressed=getch()
if keyPressed == b'1':
func_1()
elif keyPressed == b'2':
name()
elif keyPressed == b'3':
print(do_sth())
press = input("Press any key to continue....")
else:
print("No more option")