博客
关于我
笔记28 笨办法学python,自己找到的几个练习,就当作ex37来做
阅读量:363 次
发布时间:2019-03-05

本文共 2665 字,大约阅读时间需要 8 分钟。

笔记28 笨办法学python,自己找到的几个练习,就当作ex37来做

教材让我们自找代码,我找到一本网上下载的python百题练习集。立刻开始第一个练习,做成了ex37.py。做得很顺利,做完后想到和for类似的while,但把这个while套用到这个用for的代码上,试了无数次都不行。看来这两个指示符还只是近似,差别也许很大,只有在继续中理解。Ex37的扩展代码应该可以做得好一些,我在给出最初的小代码之后,再把对练习37的扩展也做一点出来。
这是最简ex37.py,然后把它缩小成ex37.0py,也能执行。

在这里插入代码片`在这里插入代码片`or i in range(1, 5):    for j in range(1, 5):        for k in range(1, 5):            if(i != k) and (i != j) and (j != k):                 print (i, j, k)

执行结果在这里插入代码片PS C:\Users\lenovo\1pythonw> python ex37.py 1 2 3 1 2 4 1 3 2 1 3 4 1 4 2 1 4 3 2 1 3 2 1 4 2 3 1 2 3 4 2 4 1 2 4 3 3 1 2 3 1 4 3 2 1 3 2 4 3 4 1 3 4 2 4 1 2 4 1 3 4 2 1 4 2 3 4 3 1 4 3 2

把这个练习缩小一部分成为ex37.0.py,也很顺利。
练习ex37.0.py在这里插入代码片for i in range(2, 6):
for j in range(2, 6):
if(i != j):
print (i, j)

执行结果如下:

在这里插入代码片PS C:\Users\lenovo\1pythonw> python ex372 32 42 53 23 43 54 24 34 55 25 35 4PS C:\Users\lenovo\1pythonw>

扩展的ex37.py也许能够顺利一点。把那个ex37.1弄得没有语法错误,可以执行的时候,结果让人哭笑不得,不是计算的结果,而是跑题后的结果。新手的尴尬也!
这是ex37.1的代码和执行结果,能够顺利执行,这是出乎意料之外的。

在这里插入代码片Range = [1, 2, 3, 4, 5]while True:        choice = input("> ")        if choice == "2" or "3":            print("do you choice which number?")        else:            print("i have no idea")

执行结果在这里插入代码片PS C:\Users\lenovo\1pythonw> pyth

2
do you choice which number?
3
do you choice which number?
5
do you choice which number?

接着又结合练习35弄出来一个ex37.2.py,没有想到很顺利,也能够顺利执行,但如果不是回答ok和no的情况,又出现name error名称错误。这个练习暂且到此,继续去看练习38吧。
这是ex37.2.py的代码和执行结果,作为笔记留存。

在这里插入代码片def begining():    print("here you will see a difficult question.")    print("there is a test that is waiting for  you.")    print("Would you recievce the test?")    answer = input("> ")    if answer == "ok":        range(1, 5)    elif answer == "no":        print("you can go through it!")    else:        dead("you are badly!")begining()for i in range(1, 5):    for j in range(1, 5):        for k in range(1, 5):            if(i != k) and (i != j) and (j != k):                 print (i, j, k)

执行结果`PS C:\Users\lenovo> cd 1pythonw
PS C:\Users\lenovo\1pythonw> python ex37.2.py
here you will see a difficult question.
there is a test that is waiting for you.
Would you recievce the test?

ok
1 2 3
1 2 4
1 3 2
1 3 4
1 4 2
1 4 3
2 1 3
2 1 4
2 3 1
2 3 4
2 4 1
2 4 3
3 1 2
3 1 4
3 2 1
3 2 4
3 4 1
3 4 2
4 1 2
4 1 3
4 2 1
4 2 3
4 3 1
4 3 2
PS C:\Users\lenovo\1pythonw> python ex37.2.py
here you will see a difficult question.
there is a test that is waiting for you.
Would you recievce the test?
no
you can go through it!
1 2 3
1 2 4
1 3 2
1 3 4
1 4 2
1 4 3
2 1 3
2 1 4
2 3 1
2 3 4
2 4 1
2 4 3
3 1 2
3 1 4
3 2 1
3 2 4
3 4 1
3 4 2
4 1 2
4 1 3
4 2 1
4 2 3
4 3 1
4 3 2
PS C:\Users\lenovo\1pythonw> python ex37.2.py在这里插入代码片`

转载地址:http://mgjg.baihongyu.com/

你可能感兴趣的文章
低代码后续发展路线图
查看>>
MobX 学习 - 04 TodoList 案例
查看>>
MobX 学习 - 06 异步任务、rootStore、数据监测
查看>>
react: antd 中 table 排序问题
查看>>
FPGA学习网站推荐
查看>>
oracle 翻译ip归属地/经纬度/定位;获取ip归属地/经纬度/定位;获取ip gps定位/lng,lat/坐标
查看>>
LeetCode:100. Same Tree相同的树(C语言)
查看>>
【个人网站搭建】GitHub pages+hexo框架下为next主题添加分类及标签
查看>>
GDB命令—jump/return/call/disassemble
查看>>
java基础--继承
查看>>
java基础--java内部类
查看>>
fastjson 反序列化源码解析
查看>>
按位与、或、非、异或总结
查看>>
TCP心跳检测包
查看>>
01 背包问题
查看>>
JVM - 参数配置影响线程数
查看>>
idea如何导入一个maven项目
查看>>
在 springboot 项目中全局处理异常
查看>>
ILI9341几个重要的命令
查看>>
AD如何对原理图进行注释
查看>>