博客
关于我
笔记28 笨办法学python,自己找到的几个练习,就当作ex37来做
阅读量:366 次
发布时间: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/

你可能感兴趣的文章
MySQL 中日志的面试题总结
查看>>
mysql 中的all,5分钟了解MySQL5.7中union all用法的黑科技
查看>>
MySQL 中的外键检查设置:SET FOREIGN_KEY_CHECKS = 1
查看>>
Mysql 中的日期时间字符串查询
查看>>
mysql 中索引的问题
查看>>
MySQL 中锁的面试题总结
查看>>
MySQL 中随机抽样:order by rand limit 的替代方案
查看>>
MySQL 为什么需要两阶段提交?
查看>>
mysql 为某个字段的值加前缀、去掉前缀
查看>>
mysql 主从
查看>>
mysql 主从 lock_mysql 主从同步权限mysql 行锁的实现
查看>>
mysql 主从互备份_mysql互为主从实战设置详解及自动化备份(Centos7.2)
查看>>
mysql 主从关系切换
查看>>
MYSQL 主从同步文档的大坑
查看>>
mysql 主键重复则覆盖_数据库主键不能重复
查看>>
Mysql 事务知识点与优化建议
查看>>
Mysql 优化 or
查看>>
mysql 优化器 key_mysql – 选择*和查询优化器
查看>>
MySQL 优化:Explain 执行计划详解
查看>>
Mysql 会导致锁表的语法
查看>>