string3 = "abc 123 $$%%"
list1 = string3.split()
print(list1)
for i in list1:
if int(i) > 0:
print("it's a number")
else:
print("not a number")
獲得以下錯誤的數值。想在給定的字符串來搜索蟒蛇
if int(i) > 0:
ValueError: invalid literal for int() with base 10: 'abc'
你認爲'int('$$ %%')'應該返回什麼? – mshsayem
[請求用戶輸入,直到他們給出有效響應]的可能重複(https://stackoverflow.com/questions/23294658/asking-the-user-for-input-until-they-give-a-valid-響應) – Reti43