3 回答

TA貢獻(xiàn)1869條經(jīng)驗 獲得超4個贊
user_string = input() # prompt the user to enter the string
result = user_string.isdigit() # check if the string is an integer string
if result: # if result is true then print yes
print("yes")
else: # else if result is false then print no
print("no")

TA貢獻(xiàn)1783條經(jīng)驗 獲得超4個贊
問題不在于您所顯示的代碼,所以它必須與 if 語句有關(guān)。不知道你的函數(shù)在做什么,我創(chuàng)建了自己的函數(shù)。
def is_integer(num):
if type(num) == int:
return True
else:
return False
您還可以通過將我的函數(shù)中的 if 語句添加到代碼中來簡化此操作,如下所示。
for i in args:
if type(i) == int:
continue

TA貢獻(xiàn)1817條經(jīng)驗 獲得超6個贊
這有效:
def skip_integers(*args):
args = list(args)
for i in args:
if type(i) == int:
args.remove(i)
return args
添加回答
舉報