Py开荒,慕课笔记练习(自用)
用来记录Python学习,纯自用,毫无可读性
2019.2.15Py部署
OS版本为CentOS7.2,自带python2.7.5
wget https://www.python.org/ftp/python/3.7.2/Python-3.7.2.tgz
前置环境
yum -y install gcc
yum -y install db4-devel libpcap-devel
yum -y install zlib zlib-devel
yum -y install bzip2 bzip2-devel
yum -y install ncurses ncurses-devel
yum -y install readline readline-devel
yum -y install openssl openssl-devel
yum -y install openssl-static
yum -y install xz lzma xz-devel
yum -y install sqlite sqlite-devel
yum -y install gdbm gdbm-devel
yum -y install tk tk-devel
yum -y install libffi-devel
yum -y install zlib*
安装
mkdir /usr/local/python3
tar -xf Python-3.7.2.tgz -C /usr/local/src/
cd /usr/local/src/Python-3.7.2
为了避免后面的pip3安装过程中出现的各种屁事,这里带参数--enable-optimizations
./configure --enable-optimizations --prefix=/usr/local/python3/
make && make install
修改配置
ln -s /usr/local/python3/bin/python3 /usr/bin/python3
由于上面的软连接到了python3,所以下面这个yum可以不用改;如果上面的软连接到了python,则下面这一行需要改
vim /usr/bin/yum,将#!/usr/bin/python改为#!/usr/bin/python2.7.5
echo "export PATH=$PATH:/usr/local/python3/bin" >> /etc/profile
source /etc/profile
检验
由上两图可知新安装的python3.7.2能正常使用ssl,此外pip3已经自动安装了
pip3 install --upgrade pip
pip3 install numpy
pip3 install pandas
pip3 install scipy
pip3 install matplotlib
pip3 install pillow
相关文档:https://www.cnblogs.com/wenchengxiaopenyou/p/5709218.html
--2019.2.18 画画
蟒蛇
import turtle as t
t.setup(1000,500) #定义窗口大小
t.penup() #抬笔
t.fd(-400) #反向前进400像素位
t.pendown() #落笔
t.pensize(10) #定义画笔宽度
t.pencolor("blue") #定义颜色
t.fd(100) #正向前进100
t.seth(90) #设置朝向往上
for i in range(5): #做一个循环,注意冒号
t.circle(-15,180)
t.circle(15,180)
t.circle(-5,90)
t.fd(20)
t.circle(10,180)
t.done()
五角星
import turtle as t
t.setup(1000,500)
t.pencolor("red")
t.pensize(5)
t.penup()
t.fd(-100)
t.pendown()
t.fillcolor("yellow")
t.begin_fill()
for i in range(5):
t.fd(200)
t.right(144)
t.end_fill()
t.done()
--2019.2.22计算
import math as m
def t(n):
y=1
for i in range(365):
if i%7 in [1,2,3,4]:
y=y*(1+n)
else:
y=y
return y
n=0
for i in range(9):
n=n+0.001
print("当N为{0:.3f}时,年终值为:{1:.3f}".format(n,t(n)))
import math as m
def t(n):
z=1
for x in range(12):
for y in range(10):
z=z*(1+n)
return z
i=0.001
j=0.001
while i<0.011:
print("当N值为{0:.3f}时,年终值为{1:.3f}".format(i,t(i)))
i=i+j