Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit c884b69

Browse files
committed
完成练习1 2
1 parent cb8d185 commit c884b69

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

‎01_base/练习/main.py‎

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
def multiplication_table():
2+
for i in range(1, 10):
3+
for j in range(1, i + 1):
4+
print('%d*%d=%d' % (j, i, i * j), end=' ') # 输出
5+
print("\n") # 每一行结束换行
6+
7+
8+
def sort_list(obj_list: list, mode: bool) -> list: # mode = True means descending
9+
for i in range(len(obj_list)):
10+
for j in range(i, len(obj_list)):
11+
if mode:
12+
if obj_list[i] < obj_list[j]:
13+
obj_list[i], obj_list[j] = obj_list[j], obj_list[i]
14+
else:
15+
if obj_list[i] > obj_list[j]:
16+
obj_list[i], obj_list[j] = obj_list[j], obj_list[i]
17+
return obj_list
18+
19+
def ID():
20+
'''
21+
学校有440人参加考试,1号考场有80个座位,要求座位号为0101--0180
22+
后面每个考场40个座位:
23+
2号考场考试号要求为0201--0240
24+
3号考场考试号要求为0301--0440
25+
后续考场以此类推,请你打印出来这些考场号吧
26+
'''
27+
for i in range(1, 440):
28+
if i <= 80:
29+
print('01{:0>2d}'.format(i))
30+
elif i <= 440:
31+
if i % 40 == 0:
32+
print('{:0>2d}{:0>2d}'.format(i // 40 - 1, 40))
33+
else:
34+
print('{:0>2d}{:0>2d}'.format(i // 40, i % 40))
35+
36+
37+
def main():
38+
# 九九乘法表
39+
# multiplication_table()
40+
41+
#冒泡法排序
42+
# test_list = [12, 47, 49, -8, -1, 24]
43+
# sorted_test_list = sort_list(test_list, False)
44+
# print(sorted_test_list)
45+
46+
ID()
47+
48+
49+
50+
51+
if __name__ == '__main__':
52+
main()

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /