PHP前端开发

Python While 循环示例

百变鹏仔 5天前 #Python
文章标签 示例


#Tasks# 2 4   6   8   10#3  6   9   12  15#1  3   5   7   9   2   4   6   8   10#10 8   6   4   2#9  7   5   3   1#1  2   3   4   5   6   7   8   9   10#1  RED BLUE RED 5 REDBLUE 7 RED BLUE RED#Task 1i=1while i <= 10:    if i%2 ==0:        print(i, end =' ')    i=i+1print('')#Task 2i=1while i <= 15:    if i%3 ==0:        print(i, end =' ')    i=i+1print('')#Task 3 using 2 loopsi=1while i<= 10:    if i%2 != 0:        print(i, end= ' ')    i=i+1i=1while i<=10:    if i%2 == 0:        print(i, end =' ')    i=i+1print('')#Task 3 using 1 loopi=1output = ''while i<= 10:    if i%2 != 0:        print(i, end= ' ')    elif i%2 == 0:        output = output + str(i) + ' '    i=i+1else:    print(output)#Task 4i=10while i>=1:    if i%2 == 0:        print(i, end =' ')    i=i-1print('')#Task 5i=10while i>=1:    if i%2 != 0:        print(i, end =' ')    i=i-1print('')#Task 6 i = 1while i<=10:    print(i, end =' ')    i=i+1print('')#Task 7i = 1while i<=10:    if i%2 == 0 and i%3 == 0:        print('REDBLUE',end =' ')    elif i%3 == 0:        print('BLUE',end= ' ')    elif i%2 == 0:        print('RED',end =' ')    else:        print(i,end =' ')    i=i+1print('')