|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
我的代码:
x = 7
i=1
while i<= 100:
if (x%2 == 1) and (x%3 == 5) and (x%5 == 4) and (x%6 == 5):
print(x)
else:
x = 7 * (i + 1)
i += 1
正确代码
1. x = 7
2. i = 1
3. flag = 0
4.
5. while i <= 100:
6. if (x%2 == 1) and (x%3 == 2) and (x%5 == 4) and (x%6==5):
7. flag = 1
8. else:
9. x = 7 * (i+1) # 根据题意,x一定是7的整数倍,所以每次乘以7
10. i += 1
11.
12. if flag == 1:
13. print('阶梯数是:', x)
14. else:
15. print('在程序限定的范围内找不到答案!')
题目:是求一个台阶有多少级,计算过程没有疑问
疑问:为什么不能再while循环中直接 print 答案,还要引入一个flag |
|