Commit aa425cc8 by BellCodeEditor

save project

parent 209cd5d4
Showing with 24 additions and 10 deletions
#定义一个函数sum_numbers() import turtle
#要求这个函数能接收一个名为num的整型参数
#要求这个函数能计算1+2+3+……+num的结果
def sun_numbers(num): pen = turtle.Turtle()
if num == 1: pen.color('sienna')
return 1 w = turtle.Screen()
w.bgcolor('wheat')
temp = sun_numbers(num - 1) pen.left(90)
return num + temp pen.up()
result = sun_numbers(100) pen.backward(150)
print(result) pen.down()
def tree(n):
if n >= 50:
pen.forward(n)
pen.right(30)
tree(n-50)
pen.left(60)
tree(n-50)
pen.right(30)
pen.up()
pen.backward(n)
turtle.done()
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment