笔记28 笨办法学python,自己找到的几个练习,就当作ex37来做
发布日期:2021-05-08 00:59:50 浏览次数:14 分类:原创文章

本文共 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在这里插入代码片`

上一篇:笔记29 笨办法学python练习38 列表前的for与while简略比较
下一篇:笔记27 笨办法学python之练习37再复习各种符号制表与熟悉符号意义与功能

发表评论

最新留言

留言是一种美德,欢迎回访!
[***.207.175.100]2025年03月19日 03时42分49秒