python 报错TypeError: sequence item 0: expected str instance, int found

代码如下

def fibo(n):
while True:
try:
n = int(n)
if n <= 0:
print(“你输入的数字小于或等于0,请输入一个大于0的正整数!”)
break
if n == 1:
print(“斐波那契数列是:1”)
break
if n > 1:
fibo_pool = [1,1]
num = 0
for i in range(2,n):
num = fibo_pool[i-2] + fibo_pool[i-1]
fibo_pool.append(num)
print(“斐波那契数列是:”," ".join(fibo_pool))
except ValueError:
print(“您输入的不是正整数,请将一个大于0正整数作为参数!”)

解决办法:
修改前:print(“斐波那契数列是:”," “.join(fibo_pool))
修改后:print(“斐波那契数列是:”,” ".join(’%s’%j for j in fibo_pool))

你可能感兴趣的:(Python,报错)