Skip to content

Commit 90d1528

Browse files
committed
更新了部分代码
1 parent e2a7bbd commit 90d1528

File tree

2 files changed

+56
-25
lines changed

2 files changed

+56
-25
lines changed

Day01-15/Day01/初识Python.md

+36-3
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,14 @@ Linux环境自带了Python 2.x版本,但是如果要更新到3.x的版本,
4747
安装依赖库(因为没有这些依赖库可能在源代码构件安装时因为缺失底层依赖库而失败)。
4848

4949
```Shell
50+
5051
yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel
5152
```
5253

5354
下载Python源代码并解压缩到指定目录。
5455

5556
```Shell
57+
5658
wget https://www.python.org/ftp/python/3.6.1/Python-3.6.1.tar.xz
5759
xz -d Python-3.6.1.tar.xz
5860
tar -xvf Python-3.6.1.tar
@@ -61,14 +63,38 @@ tar -xvf Python-3.6.1.tar
6163
切换至Python源代码目录并执行下面的命令进行配置和安装。
6264

6365
```Shell
66+
6467
cd Python-3.6.1
6568
./configure --prefix=/usr/local/python3.6 --enable-optimizations
6669
make && make install
6770
```
6871

69-
创建软链接,这样就可以直接通过python3直接启动Python解释器。
72+
配置PATH环境变量并使其生效,这需要修改用户主目录下名为.bash_profile的文件。
73+
74+
```Shell
75+
76+
cd ~
77+
vim .bash_profile
78+
```
79+
80+
```Shell
81+
82+
# 此处省略上面的代码
83+
84+
PATH=$PATH:/usr/local/python3.6/bin
85+
86+
# 此处省略下面的代码
87+
```
88+
89+
```Shell
90+
91+
source .bash_profile
92+
```
93+
94+
最后还可以创建一个符号链接(如果不知道为什么也可以暂时不管这个问题啦)。
7095

7196
```Shell
97+
7298
ln -s /usr/local/python3.6/bin/python3 /usr/bin/python3
7399
```
74100

@@ -84,11 +110,13 @@ MacOS也是自带了Python 2.x版本的,可以通过[Python的官方网站](ht
84110
在终端或命令行提示符中键入下面的命令。
85111

86112
```Shell
113+
87114
python --version
88115
```
89116
当然也可以先输入python进入交互式环境,再执行以下的代码检查Python的版本。
90117

91118
```Python
119+
92120
import sys
93121

94122
print(sys.version_info)
@@ -100,6 +128,7 @@ print(sys.version)
100128
可以用文本编辑工具(推荐使用Sublime、Atom、TextMate、VSCode等高级文本编辑工具)编写Python源代码并将其命名为hello.py保存起来,代码内容如下所示。
101129

102130
```Python
131+
103132
print('hello, world!')
104133
```
105134

@@ -108,6 +137,7 @@ print('hello, world!')
108137
切换到源代码所在的目录并执行下面的命令,看看屏幕上是否输出了"hello, world!"。
109138

110139
```Shell
140+
111141
python hello.py
112142
```
113143

@@ -119,6 +149,7 @@ python hello.py
119149
2. 多行注释 - 三个引号开头,三个引号结尾
120150

121151
```Python
152+
122153
"""
123154
124155
第一个Python程序 - hello, world!
@@ -212,8 +243,9 @@ PyCharm的安装、配置和使用我们在后面会进行介绍。
212243
1. 在Python交互环境中下面的代码查看结果并将内容翻译成中文。
213244

214245
```Python
246+
215247
import this
216-
248+
217249
Beautiful is better than ugly.
218250
Explicit is better than implicit.
219251
Simple is better than complex.
@@ -238,8 +270,9 @@ PyCharm的安装、配置和使用我们在后面会进行介绍。
238270
2. 学习使用turtle在屏幕上绘制图形。
239271

240272
```Python
273+
241274
import turtle
242-
275+
243276
turtle.pensize(4)
244277
turtle.pencolor('red')
245278
turtle.forward(100)

Day31-35/code/mycal.py

100644100755
+20-22
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,38 @@
11
#!/usr/bin/python3
22
from datetime import datetime
3+
34
import sys
45

56

67
def is_leap(year):
78
return year % 4 == 0 and year % 100 != 0 or year % 400 == 0
89

910

10-
def get_days(year, month):
11-
days = [[31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31],
12-
[31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]]
13-
return days[is_leap(year)][month - 1]
14-
15-
1611
def main():
17-
if len(sys.argv) > 1:
12+
if len(sys.argv) == 3:
1813
month = int(sys.argv[1])
1914
year = int(sys.argv[2])
2015
else:
21-
current_date = datetime.now()
22-
year = current_date.year
23-
month = current_date.month
24-
year2 = year if month >= 3 else year - 1
25-
c = year2 // 100
26-
y = year2 % 100
27-
m = month if month >= 3 else month + 12
28-
w = y + y // 4 + c // 4 - 2 * c + 26 * (m + 1) // 10
29-
w %= 7
30-
months = ['January', 'February', 'March', 'April', 'May', 'June',
31-
'July', 'August', 'September', 'October', 'November', 'December']
32-
print(f'{months[month - 1]} {year}'.center(20))
16+
now = datetime.now()
17+
date = now.date
18+
month = now.month
19+
year = now.year
20+
m, y = (month, year) if month >= 3 else (month + 12, year - 1)
21+
c, y = y // 100, y % 100
22+
w = (y + y // 4 + c // 4 - 2 * c + 26 * (m + 1) // 10) % 7
23+
month_words = [
24+
'January', 'February', 'March', 'April', 'May', 'June',
25+
'July', 'August', 'September', 'October', 'November', 'December'
26+
]
27+
print(f'{month_words[month - 1]} {year}'.center(20))
3328
print('Su Mo Tu We Th Fr Sa')
3429
print(' ' * 3 * w, end='')
35-
total_days = get_days(year, month)
36-
for day in range(1, total_days + 1):
37-
print(f'{day}'.rjust(2), end=' ')
30+
days = [
31+
[31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31],
32+
[31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
33+
][is_leap(year)][month - 1]
34+
for day in range(1, days + 1):
35+
print(str(day).rjust(2), end=' ')
3836
w += 1
3937
if w == 7:
4038
print()

0 commit comments

Comments
 (0)