我在python 3上做了一个功课,使用if,elif,else,.isdigit,.isalpha,但我不知道为什么它不起作用..
NumWord = ""
def str_analysis():
if NumWord.isalpha() == True:
print(NumWord, "is all alphabetical characters!")
elif NumWord.isdigit() == True:
if int(NumWord) == 100:
print("You found the right number!")
elif int(NumWord) >= 99:
print(NumWord, "is a pretty big number")
elif int(NumWord) <= 99:
print(NumWord, "is a smaller number than expected")
while NumWord.isalnum() == False:
NumWord = input("Enter a word or integer: ")
答案 0 :(得分:2)
你需要实际调用你写的函数:
while NumWord.isalnum() == False:
NumWord = input("Enter a word or integer: ")
str_analysis()