Python第一课:作业

 
"""输出除7以外的1-9数字"""
n = 0 while n < 10: if n == 7: pass else: print(n) n = n + 1 print("----end----")
"""1-100求和"""
1
n = 0 2 n2 = 0 3 while n < 100: 4 n = n + 1 5 n2 = n + n2 6 print(n2)

 

1 """输出1-100中的偶数"""
2 n = 1
3 while n < 101:
4     s = n % 2
5     if s == 0:
6         print(n)
7     else:
8         pass
9     n = n +1

 

"""求和1-2+3-4....99"""

n = 1
s = 0
while n < 100:
    t = n % 2
    if t == 0:
        s = s - n
    else:
        s = s + n
    n = n + 1
print(s)

 

posted @ 2022-01-21 12:40  黎明前登顶  阅读(79)  评论(0)    收藏  举报