month =
{"January" : "01",
"February" : "02" ,
"March" : "03",
"April" : "04",
"May" : "05",
"June" : "06",
"July" : "07",
"August" : "08",
"September" : "09",
"October" : "10",
"November" : "11",
"December" : "12"
}
while True:
try:
date = input("Date: ")
if date[0].isdecimal():
x, y, z = date.split("/")
while y < 31:
print(f"{z}-{x:0>2}-{y:0>2}")
elif date[0].isalpha():
x, y, z = date.split(" ")
y = y.replace(",", "")
x = x.title()
while y < 31:
if x in month:
print(f"{z}-{month.value(x)}-{y}")
except:
pass
这是我的代码,即使我使用 Ctrl+C,我也无法阻止它。接下来我可以尝试什么?
这是Cs50P中的ps3。
执行
except Exception:
而不是仅仅 except:
- 然后您就可以使用 Ctrl+C 停止程序。