第一周(1.8-1.14)

第一周 1.8~1.14

1月8号

python编译环境配置

蟒蛇小程序

import turtle
def drawSnake(rad,angle,len,neckrad):
    for i in range(len):
        turtle.circle(rad,angle)#画圆,半径为正(负),表示圆心在画笔的左边(右边)画圆,angle是弧度
        turtle.circle(-rad,angle)
    turtle.circle(rad,angle/2)
    turtle.fd(rad)
    turtle.circle(neckrad+2,180)
    turtle.fd(rad*2/3)

def main():
    turtle.setup(1300,800,0,0)#窗口大小,长宽,起始坐标
    pythonsize = 30
    turtle.pensize(pythonsize)#运行轨迹的宽度
    turtle.pencolor("blue")#颜色
    turtle.seth(-40)#角度
    drawSnake(40,80,5,pythonsize/2)

main()

第二种函数库导入方式:

from turtle import*
def drawSnake(rad,angle,len,neckrad):
    for i in range(len):
        circle(rad,angle)#画圆,半径为正(负),表示圆心在画笔的左边(右边)画圆,angle是弧度
        circle(-rad,angle)
    circle(rad,angle/2)
    fd(rad)
    circle(neckrad+2,180)
    fd(rad*2/3)

def main():
    setup(1300,800,0,0)#窗口大小,长宽,起始坐标
    pythonsize = 30
    pensize(pythonsize)#运行轨迹的宽度
    pencolor("blue")#颜色
    seth(-40)#角度
    drawSnake(40,80,5,pythonsize/2)

main()

温度转换

val = input()
if val[-1] in ['C','c']:
    f = 1.8*float(val[0:-1])+32
    print("%.2f"%f)
elif val[-1] in ['F','f']:
    c = (float(val[0:-1])-32)/1.8
    print("%.2f"%c)

eval

val = input()
if val[-1] in ['C','c']:
    f = 1.8*eval(val[0:-1])+32
    print("%.2f"%f)
elif val[-1] in ['F','f']:
    c = (eval(val[0:-1])-32)/1.8
    print("%.2f"%c)

eval函数的常用方式

彩色小蟒蛇

from turtle import*
def drawSnake(rad,angle,len,neckrad):
    for i in range(len):
        circle(rad,angle)#画圆,半径为正(负),表示圆心在画笔的左边(右边)画圆,angle是弧度
        pencolor("red")#颜色
        circle(-rad,angle)
        pencolor("yellow")#颜色
    circle(rad,angle/2)
    fd(rad)
    pencolor("blue")#颜色
    circle(neckrad+2,180)
    fd(rad*2/3)

def main():
    setup(1300,800,0,0)#窗口大小,长宽,起始坐标
    pythonsize = 30
    pensize(pythonsize)#运行轨迹的宽度
    pencolor("blue")#颜色
    seth(-40)#角度
    drawSnake(40,80,5,pythonsize/2)

main()

哈哈

三角形

from turtle import *
def main():
    setup(1000,800,200,200)
    pensize(5)
    pencolor("black")
    seth(0)
    fd(120)
    seth(120)
    fd(120)
    seth(240)
    fd(120)
main()

 

看了老友记两集,贼搞笑,哈哈。

 1月9号

绘制五角星,对那个pos()还是不太理解。

from turtle import *
fillcolor("red")
begin_fill()
while True:
    forward(200)
    right(144)
    if abs(pos())<1:
        break
end_fill()

1月15号补:pos()函数求的是Vec2D二维向量。

 

数字类型

字符串类型

输入数字,对应星期

var = input('请输入星期数字:')
week = "MonTueWenTurFriSatSun"
pos = (int(var)-1)*3
print(week[pos:pos+3])
week = "MonTueWenTurFriSatSun"
print(week.capitalize())

Montuewenturfrisatsun 只有首字母大写了,其他全小写了。

元组类型

列表类型

math库和random库

# pi.py
from random import random
from math import sqrt
from time import clock
DARTS = 120000
hits = 0
clock()
for i in range(1,DARTS):
    x, y = random(), random()
    dist = sqrt(x**2 + y**2)
    if dist <= 1.0:
        hits = hits + 1
pi = 4 * (hits/DARTS) #*4代表整圆
print("Pi的值是 %s" % pi)
print("程序运行时间是 %-5.5ss" % clock())

clock()

try 和 except

while True:
    try:
        x = int(input("number"))
        break
    except ValueError:
        print("again")
print(x)

看了老友记第一季的第三集和第四集

1月10号

小树

# drawtree.py
 
from turtle import Turtle, mainloop
 
def tree(plist, l, a, f):
    """ plist is list of pens 画笔的列表
    l is length of branch     树枝长度
    a is half of the angle between 2 branches  两个树枝角度的一半
    f is factor by which branch is shortened  比列
    from level to level."""
    if l > 5: #
        lst = []
        for p in plist:
            p.forward(l)#沿着当前的方向画画Move the turtle forward by the specified distance, in the direction the turtle is headed.
            q = p.clone()#Create and return a clone of the turtle with same position, heading and turtle properties.
            p.left(a) #Turn turtle left by angle units
            q.right(a)# turn turtle right by angle units, nits are by default degrees, but can be set via the degrees() and radians() functions.
            lst.append(p)#将元素增加到列表的最后
            lst.append(q)
        tree(lst, l*f, a, f)
   
            
 
def main():
    p = Turtle()   #生成一个对象
    p.color("green")
    p.pensize(5) #画笔轨迹长度
    #p.setundobuffer(None)
    p.hideturtle() #Make the turtle invisible. It’s a good idea to do this while you’re in the middle of doing some complex drawing,
    #because hiding the turtle speeds up the drawing observably.
    #p.speed(10)
   # p.getscreen().tracer(1,0)#Return the TurtleScreen object the turtle is drawing on.
    p.speed(1)
    #TurtleScreen methods can then be called for that object.
    p.left(90)# Turn turtle left by angle units. direction 调整画笔
 
    p.penup() #Pull the pen up – no drawing when moving.
    p.goto(0,-200)#Move turtle to an absolute position. If the pen is down, draw line. Do not change the turtle’s orientation.
    p.pendown()# Pull the pen down – drawing when moving. 这三条语句是一个组合相当于先把笔收起来再移动到指定位置,再把笔放下开始画
    #否则turtle一移动就会自动的把线画出来
 
    #t = tree([p], 200, 65, 0.6375)
    t = tree([p], 200, 65, 0.6375)
     
main()

 Supervised learning有监督学习,有训练样本,去训练得到一个最优模型,再利用这个模型将所有的输入映射为相应的输出,对输出进行简单的判断从而实现分类的目的,也就具有了对未知数据进行分类的能力。

Discriminative Algorithms 判别学习算法 http://blog.csdn.net/caimouse/article/details/60580087

Regression回归

1月11号

 贼坑,昨天到下好的numpy包,今天安装,出现各种问题,后来搜了百度,建议还是安装anaconda

终于tm安装好了……

from numpy import *
var = random.rand(4,4) #产生4*4的数组
randMat = mat(random.rand(4,4)) #mat函数将数组转换为矩阵
invRandMat = randMat.I
myEye = randMat*invRandMat
print(myEye-eye(4))# eye(4) 创建4*4的单位矩阵,计算误差

 看了老友记第一季的第五集和第六集。

1月12日

今天准备去内蒙古,上午取票,买点东西,下午做火车,看了王牌特工一二部。

1月13日

今天到gf家,上午吃了饭,见了亲戚,下午休息一下午,醒来后,觉得做火车实在不划算,晚上睡觉睡不好,第二天还要补觉,很耽误时间,以后工作后,能做飞机就做飞机,或者高铁。

晚上看了老友记第七集。

1月14日

今天用sublime text3安装了anaconda,又设了快捷键,以后开始用sublime text啦。

 

posted @ 2018-01-08 10:35  卷珠帘  阅读(377)  评论(3编辑  收藏  举报