Discuss / Python / 这章是我卡的时间最长的一章

这章是我卡的时间最长的一章

Topic source

哎呀博雅

#1 Created at ... [Delete] [Delete and Lock User]

交作业写一个死循环

我能想到的

第一个情况

n = 1
while n <= 100:
    print(n)
print('END')

因为每次判断n都小于100所以无限循环执行>>>1 1 1 1 1 1 1 

第二种情况是

n = 1
while n <= 100:
    print(n)
    n = n - 1
print('END')

执行后还是因为每次判断n都小于正整数100,所以执行打印后n 在减1,所以无线循环下去

第三种情况是

n = 1
while n <= 100:
    if n == 99:        
       n = n - 99
    print(n)
    n = n + 1
print('END')

……

思考,取模干什么用的????


  • 1

Reply