我有以下代码:
CVE-2015-7547-client: getaddrinfo: Name or service not known
我想创建一个用户输入的数字列表。可以帮一下吗?
答案 0 :(得分:1)
number_list = []
while True:
line = raw_input('Enter number:')
if line == 'done':
break
try:
n = int(line)
number_list.append(n)
except ValueError:
print 'invalid input'
print 'Done!'
print number_list
答案 1 :(得分:0)
还有一个变种:
res = []
line = raw_input('Enter number:')
while line.lower() != 'done':
try:
res.append(int(line))
except ValueError:
print 'Invalid input'
line = raw_input('Enter number:')
print 'Done!'
print " ".join(map(str, res))