博客
关于我
笔记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 高可用性之keepalived+mysql双主
查看>>
MySQL 高性能优化规范建议
查看>>
mysql 默认事务隔离级别下锁分析
查看>>
Mysql--逻辑架构
查看>>
MySql-2019-4-21-复习
查看>>
mysql-5.6.17-win32免安装版配置
查看>>
mysql-5.7.18安装
查看>>
MySQL-Buffer的应用
查看>>
mysql-cluster 安装篇(1)---简介
查看>>
mysql-connector-java.jar乱码,最新版mysql-connector-java-8.0.15.jar,如何愉快的进行JDBC操作...
查看>>
mysql-connector-java各种版本下载地址
查看>>
mysql-EXPLAIN
查看>>
MySQL-Explain的详解
查看>>
mysql-group_concat
查看>>
MySQL-redo日志
查看>>
MySQL-【1】配置
查看>>
MySQL-【4】基本操作
查看>>
Mysql-丢失更新
查看>>
Mysql-事务阻塞
查看>>
Mysql-存储引擎
查看>>