日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

第五次课 课上代码

發布時間:2023/12/13 编程问答 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 第五次课 课上代码 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

第五次

?

雙重循環——排序(復習)

While循環

Break continue

字符串(len,取值改值,格式化)

列表生成式

>>> for i in range(4):
?? ?for j in range(4):
?? ??? ?print(i,j)

?? ??? ?
0 0
0 1
0 2
0 3
1 0
1 1
1 2
1 3
2 0
2 1
2 2
2 3
3 0
3 1
3 2
3 3
>>> for i in range(2):
?? ?for j in range(2):
?? ??? ?for k in range(2):
?? ??? ??? ?print(i,j)

?? ??? ??? ?
0 0
0 0
0 1
0 1
1 0
1 0
1 1
1 1
>>> for i in range(2):
?? ?for j in range(2):
?? ??? ?for k in range(2):
?? ??? ??? ?print(i,j,k)

?? ??? ??? ?
0 0 0
0 0 1
0 1 0
0 1 1
1 0 0
1 0 1
1 1 0
1 1 1
>>> for i in range(2):
?? ?for j in range(2):
?? ??? ?for k in range(2):
?? ??? ??? ?print(j,k)

?? ??? ??? ?
0 0
0 1
1 0
1 1
0 0
0 1
1 0
1 1
>>> l=[4,5,7,8,2,2]
>>> for i in range(1,len(l)):#意義是第i個元素開始插入i之前的序列(已經有序)
?? ? ? ?for j in range(i,0,-1):#只要比它之前的元素小就交換
?? ??? ?if l[j]<l[j-1]:
?? ??? ? ? ?l[j],l[j-1]=l[j-1],l[j]
?? ??? ?else:
?? ??? ? ? ?break#直到比前一個元素大
?? ??? ?
SyntaxError: inconsistent use of tabs and spaces in indentation
>>> l=[1,3,5,7,9]
>>> x=4
>>> l=[3,7,5,6,4]
>>> while x>8:
?? ?print(x)

?? ?
>>> while x<8:
?? ?print(x)
?? ?x=x+1

?? ?
4
5
6
7
>>> while 0:
?? ?print(1)

?? ?
>>> while x<8:
?? ?print(1)
?? ?if x>10:
?? ??? ?break
?? ?x=x+1

?? ?
>>> while 1:
?? ?print(1)
?? ?if x>10:
?? ??? ?break
?? ?x=x+1

?? ?
1
1
1
1
>>> l=[3,7,5,6,4]
>>> for i in range(1,len(l)):#意義是第i個元素開始插入i之前的序列(已經有序)
?? ? ? ?for j in range(i,0,-1):#只要比它之前的元素小就交換
?? ??? ?if l[j]<l[j-1]:
?? ??? ? ? ?l[j],l[j-1]=l[j-1],l[j]
?? ??? ?else:
?? ??? ? ? ?continue#直到比前一個元素大
?? ??? ?
SyntaxError: inconsistent use of tabs and spaces in indentation
>>> for i in range(1,len(l)):#意義是第i個元素開始插入i之前的序列(已經有序)
?? ? ? ?for j in range(i,0,-1):#只要比它之前的元素小就交換
?? ??? ?if l[j]<l[j-1]:
?? ??? ? ? ?l[j],l[j-1]=l[j-1],l[j]
?? ??? ?else:
?? ??? ? ? ?continue
?? ??? ?
SyntaxError: inconsistent use of tabs and spaces in indentation
>>> for i in range(5):
?? ?if i%2==0:
?? ??? ?continue
?? ?print(i)

?? ?
1
3
>>> for i in range(100):
?? ?if i%2==0:
?? ??? ?continue
?? ?print(i,end=" ")

?? ?
1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49 51 53 55 57 59 61 63 65 67 69 71 73 75 77 79 81 83 85 87 89 91 93 95 97 99?
>>> l='0123456'
>>> len(l)
7
>>> l[0]
'0'
>>> l[0]=1
Traceback (most recent call last):
? File "<pyshell#48>", line 1, in <module>
? ? l[0]=1
TypeError: 'str' object does not support item assignment
>>> l=l[:2]+'9'+l[3:]
>>> print(l)
0193456
>>> 'Hi, %s, you have $%d.' % ('Michael', 1000000)
'Hi, Michael, you have $1000000.'
>>> 'Hi, %s, you have $%5d.' % ('Michael', 5)
'Hi, Michael, you have $ ? ?5.'
>>> 1*1=1
SyntaxError: can't assign to operator
>>> 9*9=81
SyntaxError: can't assign to operator
>>> 9*2=18
SyntaxError: can't assign to operator
9*2=18
>>> l=[0,1,2,3]
>>> l=[i for i in range(5)]
>>> print(i)
99
>>> print(l)
[0, 1, 2, 3, 4]
>>> l=[0]*10
>>> print(l)
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
>>> l=[0 for i in range(5)]
>>> print(l)
[0, 0, 0, 0, 0]
>>> l[0,1,2,3,4]
Traceback (most recent call last):
? File "<pyshell#64>", line 1, in <module>
? ? l[0,1,2,3,4]
TypeError: list indices must be integers or slices, not tuple
>>> l=[0,1,2,3,4]
>>> l=[[0],[1],[2]]
>>> l=[[0,1],[1,2],[2,3]]
>>> l[0][0]
0
>>> l[1][0]
1
>>> i=0
>>> print(i)
0
>>> l=[[0,1],[1,2],[2,3]]
>>> for i in l:
?? ?print(i)

?? ?
[0, 1]
[1, 2]
[2, 3]
>>> print("liurujia")
liurujia
>>>?

總結

以上是生活随笔為你收集整理的第五次课 课上代码的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。