分享给Python新手们的几道简单练习题
作者:洛柯 时间:2021-08-01 22:05:14
前言
本文主要给大家分享了一些简单的Python练习题,对学习python的新手们来说是个不错的练习问题,下面话不多说了,来一起看看详细的介绍吧。
第一题:使用while循环输入 1 2 3 4 5 6 8 9 10
a = 0
while a < 10:
a +=1
if a == 7:
continue
print(a)
第二题:求1-100的所有数的和
第一种方法:
a = 0
b = 1
while b <= 100:
a = a + b
b += 1
print(a)
第二种方法:
a = 0
for i in range(101):
a = a + i
print(a)
第三题:输出 1-100 内的所有奇数
a = 0
while a <= 100:
a += 1
if(a%2) == 0:
print(a)
第四题:输出 1-100 内的所有偶数
第一种方法:
a = 0
while a <= 100:
a += 1
if(a%2) == 0:
print(a-2+1)
第二种方法:
a = 0
while a <= 99:
a += 1
if(a%2) != 0:
print(a)
第五题:求1-2+3-4+5 ... 99的所有数的和
a = 0
b = 0
while a < 99:
a += 1
if a%2 == 1:
b += a
else:
b -= a
print(b)
第六题:用户登陆(三次机会重试)
a = 0
while a < 3:
name = input("请输入用户名: ")
password = input("请输入密码: ")
a += 1
if name == 'wxd' and password == '123456':
print("登陆成功")
exit()
else:
print("输入错误,请重新输入")
print("输入错误三次,退出")
来源:http://www.cnblogs.com/-luoke/p/7564982.html
标签:python,新手,练习题
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
详解Python爬虫的基本写法
2022-12-26 07:49:45
Python 多线程,threading模块,创建子线程的两种方式示例
2021-06-29 15:49:32
js实现滑动进度条效果
2023-08-24 03:47:39
![](https://img.aspxhome.com/file/2023/7/56257_0s.gif)
深入理解Python对Json的解析
2023-10-18 20:01:38
![](https://img.aspxhome.com/file/2023/6/99006_0s.gif)
python单线程实现多个定时器示例
2023-05-11 08:59:18
巧用XSL和ASP在线编辑XML文档
2008-10-25 14:54:00
python多线程之事件Event的使用详解
2022-12-21 11:46:10
粗暴解决CUDA out of memory的问题
2023-05-12 05:40:00
Python基于回溯法子集树模板解决旅行商问题(TSP)实例
2023-04-27 15:39:32
![](https://img.aspxhome.com/file/2023/5/82665_0s.jpg)
JavaScript控制flash操作 兼容IE FF[译]
2009-11-29 16:28:00
![](https://img.aspxhome.com/file/UploadPic/200911/29/flashjr-60s.jpg)
微软建议的ASP性能优化28条守则(9)
2005-05-30 16:05:00
python查找指定文件夹下所有文件并按修改时间倒序排列的方法
2023-08-08 01:11:57
Python 3.6 读取并操作文件内容的实例
2021-11-21 16:52:14
Python压缩模块zipfile实现原理及用法解析
2023-07-13 03:01:46
使用Python实现从各个子文件夹中复制指定文件的方法
2023-11-09 12:04:05
pycharm查看变量值的4种方法汇总
2022-04-17 04:37:37
![](https://img.aspxhome.com/file/2023/5/105025_0s.png)
Python reshape的用法及多个二维数组合并为三维数组的实例
2021-12-18 10:29:25
![](https://img.aspxhome.com/file/2023/4/102324_0s.jpg)
python3+PyQt5+Qt Designer实现堆叠窗口部件
2023-12-30 01:21:55
![](https://img.aspxhome.com/file/2023/6/93566_0s.png)
python实现的批量分析xml标签中各个类别个数功能示例
2021-01-16 00:22:00
打分进化史
2009-12-24 12:20:00
![](https://img.aspxhome.com/file/UploadPic/20101/11/taobao-84s.png)