while循环练习-打印奇数和偶数、死循环

打印出0-10之间的所有偶数:

方法1:

1 num = 2
2 while num < 10:
3     print(num)
4     num += 2

方法2:

1 num = 1
2 while num < 10:
3     if num%2 == 0:
4         print(num)
5     num +=1

打印出0-10之间的所有奇数:

方法1:

1 num = 1
2 while num < 10:
3     print(num)
4     num += 2

方法2:

1 num = 0
2 while num < 10:
3     if num%2 == 1:
4         print(num)
5     num +=1

死循环:

1 num = 1
2 while num < 10:
3     print(num)

 

转载于:https://www.cnblogs.com/yhgszi/p/8206114.html

你可能感兴趣的:(while循环练习-打印奇数和偶数、死循环)