码迷,mamicode.com
首页 > 编程语言 > 详细

Python基础

时间:2018-03-14 19:42:17      阅读:280      评论:0      收藏:0      [点我收藏+]

标签:span   body   方法   yellow   综合   name   charm   pychar   center   

Pycharm开发环境设置与熟悉。

 

练习基本输入输出:

print(‘你好,{}.‘.format(name))

uprint(sys.argv)

 

库的使用方法:

import ...

from ... import ...

 

条件语句:

    if (abs(pos()))<1:

        break

 

循环语句:

for i in range(5):

while True:

 

函数定义:

def mygoto(x,y):

def drawjx(r):

 

综合练习:画一面五星红旗,将代码与运行截图发布博客交作业。

import time
import turtle
import os


def draw_rectangle(start_x, start_y, rec_x, rec_y):
    turtle.goto(start_x, start_y)
    turtle.color(red)
    turtle.fillcolor(red)
    turtle.begin_fill()
    for i in range(2):
        turtle.forward(rec_x)
        turtle.left(90)
        turtle.forward(rec_y)
        turtle.left(90)
    turtle.end_fill()


def draw_star(center_x, center_y, radius):
    turtle.setpos(center_x, center_y)
    # find the peak of the five-pointed star
    pt1 = turtle.pos()
    turtle.circle(-radius, 72)
    pt2 = turtle.pos()
    turtle.circle(-radius, 72)
    pt3 = turtle.pos()
    turtle.circle(-radius, 72)
    pt4 = turtle.pos()
    turtle.circle(-radius, 72)
    pt5 = turtle.pos()
    # draw the five-pointed star
    turtle.color(yellow, yellow)
    turtle.fill(True)
    turtle.goto(pt3)
    turtle.goto(pt1)
    turtle.goto(pt4)
    turtle.goto(pt2)
    turtle.goto(pt5)
    turtle.fill(False)


# start the project
turtle.speed(5)
turtle.penup()
# draw the rectangle
star_x = -320
star_y = -260
len_x = 660
len_y = 440
draw_rectangle(star_x, star_y, len_x, len_y)
# draw the big star
pice = 660 / 30
big_center_x = star_x + 5 * pice
big_center_y = star_y + len_y - pice * 5
turtle.goto(big_center_x, big_center_y)
turtle.left(90)
turtle.forward(pice * 3)
turtle.right(90)
draw_star(turtle.xcor(), turtle.ycor(), pice * 3)
# draw the small star
turtle.goto(star_x + 10 * pice, star_y + len_y - pice * 2)
turtle.left(turtle.towards(big_center_x, big_center_y) - turtle.heading())
turtle.forward(pice)
turtle.right(90)
draw_star(turtle.xcor(), turtle.ycor(), pice)
# draw the second star
turtle.goto(star_x + pice * 12, star_y + len_y - pice * 4)
turtle.left(turtle.towards(big_center_x, big_center_y) - turtle.heading())
turtle.forward(pice)
turtle.right(90)
draw_star(turtle.xcor(), turtle.ycor(), pice)
# draw the third
turtle.goto(star_x + pice * 12, star_y + len_y - 7 * pice)
turtle.left(turtle.towards(big_center_x, big_center_y) - turtle.heading())
turtle.forward(pice)
turtle.right(90)
draw_star(turtle.xcor(), turtle.ycor(), pice)
# draw the final
turtle.goto(star_x + pice * 10, star_y + len_y - 9 * pice)
turtle.left(turtle.towards(big_center_x, big_center_y) - turtle.heading())
turtle.forward(pice)
turtle.right(90)
draw_star(turtle.xcor(), turtle.ycor(), pice)

turtle.ht()
time.sleep(3)
os._exit(1)

技术分享图片

Python基础

标签:span   body   方法   yellow   综合   name   charm   pychar   center   

原文地址:https://www.cnblogs.com/swxvico/p/8569516.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!