擅长:python、mysql、java
<p>改编自Trenton McKinney标记的副本</p>
<p><strong>请尝试更多测试用例,以防我错了</strong></p>
<p>对于我所尝试的,我得到了结果输出</p>
<pre><code>while True:
test=input("Nums sep by comma: ")
test_list = test.split(',')
try:
numbers = [int(x.strip()) for x in test_list]
except:
print('please try again, with only numbers separated by commas (e.g. "1, 5, 3")')
continue
else:
print(numbers)
break
print(numbers)
</code></pre>
<p>测试</p>
<pre><code>Nums sep by comma: 1, asdf
please try again, with only numbers separated by commas (e.g. "1, 5, 3")
Nums sep by comma: 1, 2, 5
[1, 2, 5]
</code></pre>