所以我正在编写一个小代码,当用户按下“输入”时,我想退出一个特定的循环。键。我是初学者所以请帮助我。
代码:
def leapYear(year):
if year%4==0:
print("\nThe year", year, "is a leap year!")
else:
print("\nThe year", year, "is NOT a leap year!")
print('')
main()
def main():
while True:
year = int(input("Please enter a 4-digit year \n[or 'ENTER' to quit]: "))
if year == "":
break
leapYear(year)
答案 0 :(得分:1)
尝试针对空字符串检查输入:
while True:
text = raw_input("Prompt (or press Enter to Exit): ")
if text == "":
break
# Code if the user inputted something