问题请教,帮忙检查问题
下面这段代码有什么问题,运行报错,怎么修改,各位大神指点一下!def time(n):
n1=1
n2=1
n3=1
if n < 1:
print('输入错误!')
return -1
while (n-2) > 0:
n3 = n2+n1
n1 = n2
n2 = n3
n -= 1
return n3
yuefen = int(input( '请输入月份:')):
duishu = time(yuefen)
print('当经过%d个月时会有%d对兔子!' % (yuefen,duishu))
17 行你的代码不小心多加了个冒号,去掉即可正常执行代码,参考代码:
def time(n):
n1=1
n2=1
n3=1
if n < 1:
print('输入错误!')
return -1
while (n-2) > 0:
n3 = n2+n1
n1 = n2
n2 = n3
n -= 1
return n3
yuefen = int(input( '请输入月份:'))
duishu = time(yuefen)
print('当经过%d个月时会有%d对兔子!' % (yuefen,duishu))
页:
[1]