day03

pycharm常用快捷键

  • ctrl+c:选中内容复制;不选中内容时,复制当前行。
  • ctrl+x:选中内容剪切;不选中内容时,剪切当前行。
  • ctrl+v:粘贴
  • ctrl+d:复制当前行到下一行。
  • ctrl+y:删除当前这一行。
  • shift+enter:跳到下一行。
  • ctrl+/:添加注释。
  • tab:缩进。
  • shift+tab:取消缩进。
  • ctrl+f:查找。
  • ctrl+shift+r:在当前项目中查找。
  • ctrl+z:回到上一步操作
  • shift+ctrl+z:回到下一步
  • home 回到行首
  • end 回到行尾
  • ctrl+home 跳到文件首位
  • ctrl+end 跳到文件末尾

变量

什么是变量

变化的量,描述某种事物的属性

定义变量

变量名 赋值符号(=) 具体的值

name = 'reese'
age = 23
gender = 'male'
height = 180
weight = 150

变量的组成

  1. 变量名:变量名用来引用变量值
  2. 赋值符号:赋值
  3. 变量值:存放数据,记录状态

变量名的命名规范

  • 变量名必须要有意义
  • 变量名由字母/数字/下划线(_)组成,不能以数字开头
  • 变量不能以关键字命名
'''python关键字:

['and', 'as', 'assert', 'break', 'class', 
'continue', 'def', 'del', 'elif', 'else', 
'except', 'exec', 'finally', 'for', 'from', 
'global', 'if', 'import', 'in', 'is', 'lambda',
 'not', 'or', 'pass', 'print', 'raise', 'return', 
 'try', 'while', 'with', 'yield']
'''


变量名的两种方式

  • 下划线命名 :(推荐)

    age_of_reese

  • 驼峰体:

    AgeOfReese

注释

单行注释

print('jbhdhjaf')  # 打印一串字符

# name = 'reese'
# age = 19
  • 单行注释 解释前面的代码
  • 单行注释 使得后面的代码失效,不运行代码

多行注释

三单引号/三双引号

'''
print('jbhdhjaf')
print('jbhdhjaf')
print('jbhdhjaf')
'''

turtle库

turtle的一些用法

# 首先导包
import turtle

# 画布布局
turtle.setup(800,600)

# 控制画笔
turtle.penup()  # 抬笔 
turtle.pendown()  # 落笔

# 空间布局 
turtle.goto(100,50)   # 到达某一个点,坐标

# 控制画笔前进后退
turtle.pensize(10)  # 画笔大小
turtle.fd(100)  # 前进
turtle.bk(200)  # 后退
turtle.circle(20,120)  # 画圆,半径为20,弧度为120

# 颜色体系
turtle.pencolor('red')  # 画笔颜色

turtle.colormode(255)
turtle.pencolor(255,0,0) # 画笔颜色

turtle.colormode(1)
turtle.pencolor(1,0,1)

# 填充颜色
turtle.fillcolor('yellow')
turtle.begin_fill()
turtle.end_fill()

turtle.done()  #  固定画布

# 画五角星
import turtle

turtle.setup(800,600)
turtle.penup()
turtle.goto(-100,100)
turtle.pendown()
turtle.fillcolor('red')
turtle.begin_fill()

turtle.fd(200)
turtle.right(144)
turtle.fd(200)
turtle.right(144)
turtle.fd(200)
turtle.right(144)
turtle.fd(200)
turtle.right(144)
turtle.fd(200)
turtle.right(144)
turtle.end_fill()

turtle.done()

五角星

# 画国旗
import turtle as t

t.setup(900,600)
# 主星
t.bgcolor("red")
t.pencolor('yellow')
t.fillcolor('yellow')
t.begin_fill()
t.penup()
t.goto(-420,150)
t.pendown()
t.begin_fill()
t.fd(150)
t.right(144)
t.fd(150)
t.right(144)
t.fd(150)
t.right(144)
t.fd(150)
t.right(144)
t.fd(150)
t.right(144)
t.end_fill()

# 第一颗星
t.penup()
t.goto(-200,270)
t.pendown()
t.seth(305)
t.fillcolor('yellow')
t.begin_fill()
t.fd(50)
t.right(144)
t.fd(50)
t.right(144)
t.fd(50)
t.right(144)
t.fd(50)
t.right(144)
t.fd(50)
t.right(144)
t.end_fill()

# 第二颗星
t.penup()
t.goto(-100,180)
t.pendown()
t.seth(30)
t.fillcolor('yellow')
t.begin_fill()
t.fd(50)
t.right(144)
t.fd(50)
t.right(144)
t.fd(50)
t.right(144)
t.fd(50)
t.right(144)
t.fd(50)
t.right(144)
t.end_fill()

# 第三颗星
t.penup()
t.goto(-100,75)
t.pendown()
t.seth(5)
t.fillcolor('yellow')
t.begin_fill()
t.fd(50)
t.right(144)
t.fd(50)
t.right(144)
t.fd(50)
t.right(144)
t.fd(50)
t.right(144)
t.fd(50)
t.right(144)
t.end_fill()

# 第四颗星
t.penup()
t.goto(-200,15)
t.pendown()
t.seth(300)
t.fillcolor('yellow')
t.begin_fill()
t.fd(50)
t.right(144)
t.fd(50)
t.right(144)
t.fd(50)
t.right(144)
t.fd(50)
t.right(144)
t.fd(50)
t.right(144)
t.end_fill()

t.done()

国旗

posted @ 2019-08-23 17:23  SetCreed  阅读(230)  评论(0编辑  收藏  举报