python学习日记

python差不多是自学了 各种杂七杂八的

1.turtle部分

import turtle as t

一些基础的设置:

def set():
    t.colormode(255)  #颜色
    t.pensize(5)
    t.speed(0)
    #t.shape('turtle')
    t.hideturtle()
    t.penup()
View Code

如何画一个心(可以把speed设置一下 现在速度不统一)

def heart():
    t.pencolor(250,128,114)
    t.fillcolor(255,192,203)
    t.goto(-180,120)
    t.begin_fill()
    t.left(60)
    t.pendown()
    for i in range(200):
        t.forward(1)
        t.right(1)
    t.forward(114)
    t.penup()

    t.goto(-180,120)
    t.setheading(120)
    t.pendown()
    for i in range(200):
        t.forward(1)
        t.left(1)
    t.forward(114)
    t.end_fill()
    t.penup()
View Code

画完之后不立刻关掉框:t.done()

其他图案再慢慢补充

 

2.

字符与数字的转换:

ord(c):参数是长度为1的字符串,简称字符。当参数为统一对象时(unicode object),返回能代表该字符的统一编码,当参数为8比特的字符串时,返回该字节的值。例如,ord('a')返回整形数值97,ord(u'\u2020')返回8224。

chr(i):返回一个字符,字符的ascii码等于参数中的整形数值。例如chr(97)返回字符'a',该方法是ord()的反方法。参数必须是0-255的整形数值,否则会抛出valueError错误。

eg

print(chr(ord('A')+25))
View Code

 

posted @ 2020-03-19 21:12  YWQQwQ  阅读(90)  评论(0)    收藏  举报