Discuss / Python / for循环100以内奇数累加,作业for与while循环

for循环100以内奇数累加,作业for与while循环

Topic source

Dreamer_DK

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

for循环100以内奇数累加:

sum = 0
for x in range(100):
    if (x % 2) == 1:
        sum = sum + x
print(sum)

for循环实现作业:

for x in L:
    print('hello,',x)

while循环实现作业:

n = 0
while n <= 2:
    print('hello, %s' % L[n])
    n = n + 1

  • 1

Reply