본문으로 바로가기

Python :: 함수 - 연습문제

category Programing/Python 2017. 6. 12. 04:19

1. 눈사람 그리기


import turtle

t = turtle.Turtle()

t.shape("turtle")

t.color("black", "white")

s = turtle.Screen(); s.bgcolor('skyblue');


def draw_snowman(x, y):

    t.up()

    t.goto(x, y)

    t.down()

    t.begin_fill()

    t.circle(20)

    t.end_fill()

    t.goto(x, y-25)

    t.setheading(135)

    t.forward(50)

    t.backward(50)


    t.setheading(30)

    t.forward(50)

    t.backward(50)

    t.setheading(0) #거북이 방향 오른쪽


    t.begin_fill()

    t.circle(15)

    t.end_fill()

    t.goto(x, y-70)

    t.begin_fill()

    t.circle(30)

    t.end_fill()


draw_snowman(0, 0)

draw_snowman(100, 0)

draw_snowman(200, 0)


수학적 함수를 계산하는 함수를 작성


import turtle 

t = turtle.Turtle()

t.shape("turtle")

t.speed(0)


def f(x):

    return x**2+1


t.goto(200, 0)

t.goto(0, 0)

t.goto(0, 200)

t.goto(0, 0)


for x in range(150):

t.goto(x, int(0.01*f(x)))