我试图检测一个按键,以确定用户是否想再次播放,但是msvcrt.getch公司()只是不适合我。这是我的代码:
import msvcrt
#the game here
print "Do you want to continue? Y/N"
if msvcrt.getch() == 'Y' or msvcrt.getch() == 'y':
print"Let's play again!"
print"-----------------"
elif msvcrt.getch() == 'N' or msvcrt.getch() == 'n' :
"Okay, hope you had fun"
break
有什么建议吗?在
编辑:下面的答案在命令行上有效,因为某些原因,这些答案在PyCharm中不起作用
您应该只调用
msvcrt.getch()
一次。将代码改为如下所示:相关问题 更多 >
编程相关推荐