python 第006讲 计算台阶问题,自己改编的代码,不向小甲鱼那么改,怎么退出无限循环
x=7i=1
while i<=20:
if(x%7==0)and(x%2==1)and(x%3==2)and(x%5==4)and(x%6==5):
print(x,'阶数是')
else:
x=7*(i+1)
i+=1
print('在所给范围内无答案') 加个break
x = 7
i = 1
while i <= 20:
if (x % 7 == 0) and (x % 2 == 1) and (x % 3 == 2) and (x % 5 == 4) and (x % 6 == 5):
print('阶梯数是', x)
break
else:
x = 7 * (i + 1)
i += 1
else:
print('在所给范围内无答案')
疾风怪盗 发表于 2020-9-16 14:00
加个break
非常感谢
页:
[1]