您好,欢迎来到外链网!
当前位置:外链网 » 站长资讯 » 专业问答 » 文章详细 订阅RssFeed

python中的isalpha,python isalpha函数用法

来源:互联网 浏览:122次 时间:2023-04-08

你有点问题。在

首先,不要将输入转换为str。它已经作为字符串从input传入。在

第二,你永远不会用你想要捕捉的异常来引发异常,因为你的输入在try/except之外。不仅如此,如果输入abcd1234之类的内容,也不会引发异常。这仍然是一个有效的字符串。在

你有奖金问题。千万不要抓住打开的Exception。总是明确你想要捕捉什么样的异常。不过,你不需要尝试一下。相反,只需检查您是否有有效的条目并继续您的逻辑。在

只需删除try/except甚至isalnum检查,只需检查输入的字符串是否与您要查找的字符串匹配。如果没有,则输出某种错误消息:def bear_room():

print("there's a bear here")

print("the bear has a bunch of honey")

print("the fat bear is front of another door")

print("how are you going to move the bear?")

choice = input("(Taunt bear, take honey, open door?: ")

if choice == "take honey":

print("the bear looks at you then slaps your face off")

elif choice == "open door":

print("get the hell out")

else:

print("Invalid 便宜香港vps entry")

bear_room()

bear_room()

13889470