我是 python 编码的新手,我正在填写一些需要大量输入的代码。它要求的一件事是,如果用户按下回车键并且没有输入任何输入,程序就执行一个操作。我的问题是你如何让 python 来检查。可不可能是:
if input == "":
#action
Run Code Online (Sandbox Code Playgroud)
或者是别的什么?感谢您的帮助。
编辑:这是我的代码目前的样子以供参考。
try:
coinN= int(input("Enter next coin: "))
if coinN == "" and totalcoin == rand:
print("Congratulations. Your calculations were a success.")
if coinN == "" and totalcoin < rand:
print("I'm sorry. You only entered",totalcoin,"cents.")
except ValueError:
print("Invalid Input")
else:
totalcoin = totalcoin + coinN
Run Code Online (Sandbox Code Playgroud)