004-小试牛刀
1、while循环语句、if语句以及取余法的应用
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#求1到100所有数的总和 n = 1 m = 2 while m <= 100: n=n+m m=m+1 print(n,m) print ("--end---")
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#求1-2+3+4+5....99的和 n = 1 m = 3 while m <100: n=n+m m=m+1 n=n-2 print(n,m) print ("--end---")
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#循环输出1、2、3、4、5、6、8、9、10 n =1 while n < 11: if n == 7: pass else: print(n) n = n + 1 print ("--end---")
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#求1到100所有奇数 n = 1 while n < 101: if n % 2 == 1: print(n) n = n+1 print ("--end---")
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#求1到100所有奇数之和 n = 1 m = 0 while n < 101: if n % 2 == 1: m = m + n n = n+1 print (m,n) print ("--end---")
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#输出1到100所有偶数 n = 1 while n < 101: if n % 2 == 0: print(n) n = n+1 print ("--end---")
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#求1到100所有偶数之和 n = 1 m = 0 while n < 101: if n % 2 == 0: m = m + n n = n+1 print (m,n) print ("--end---")
作者:小飞
备注:本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须在文章页面给出原文连接,否则保留追究法律责任的权利。
备注:部分图片下载来源于网络,如若有侵权,请联系本人予以删除,邮箱:2777418194@qq.com。
本博客作为本人软件学习记录而用,不提供任何软件的下载链接,敬请谅解
可关注本人微信公众号【软件开发部门】回复“资源”获取部分免费资源
![](https://images.cnblogs.com/cnblogs_com/xf23554/1929733/o_2102070724551.jpg)
![](https://images.cnblogs.com/cnblogs_com/xf23554/1929733/o_210207082121niu.gif)