标签:col python style class int 循环 奇数 pytho +=
1 num=1 2 while num<=10: 3 print(num) 4 num+=1
结果为1,2,3,4,5,6,7,8,9,10
1 num=1 2 while num<=10: 3 num+=1 4 print(num)
结果为2,3,4,5,6,7,8,9,10,11
输出1-100之间的偶数:
方法一:
1 num=22 while num<=100: 3 print(num) 4 num+=2
方法二:
1 num=1 2 while num<=100: 3 if num%2==0: 4 print(num) 5 num+=1
输出1-100之间所有的奇数:
1 num=1 2 while num<=100: 3 if num%2==1: 4 print(num) 5 num += 1
标签:col python style class int 循环 奇数 pytho +=
原文地址:https://www.cnblogs.com/Crystal0717/p/12287815.html