我无法停止我的Python程序,请帮助我

问题描述 投票:0回答:1
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

python cs50 infinite-loop break
1个回答
0
投票

执行

except Exception:
而不是仅仅
except:
- 然后您就可以使用 Ctrl+C 停止程序。

© www.soinside.com 2019 - 2024. All rights reserved.