当我运行这个时,我得到以下类型不匹配错误,我不知道为什么var被认为是一个字符串而不是一个int。我在这里错过了什么吗?
`Traceback (most recent call last):
File "main.py", line 5, in <module>
test.assert_equals(productFib(4895), [55, 89, True])
File "/home/codewarrior/solution.py", line 7, in productFib
while var <= prod:
TypeError: unorderable types: str() <= int()`
def productFib(prod):
# create Fibonacci array
var = 0
elem = 0
boo = False
while var <= prod:
var = fib(elem)*fib(elem+1)
if var == prod:
boo = True
elem += 1
return [fib(elem), fib(elem+1), boo]
# function to return what the nth fibonacci number is
def fib(n):
if n < 0:
return "Incorrect input"
elif n == 1:
return 0
elif n == 2:
return 1
else:
return fib(n-1)+fib(n-2)
红颜莎娜
哈士奇WWW
相关分类