Hello everyone, I'm cabbage carrot balls
Life is too short, Python is a song
project import
Version V5.0: Realize the number of times the user decides to repeat the drawing of the five-pointed star, the size of the five-pointed star, the fill color, etc.
Project analysis - clarifying ideas
- Analyze the problem: The computational part of the analysis problem
- Defining the problem: dividing the input, processing, and output parts of the problem (IPO)
- Designing Algorithms: The Heart of the Computational Section
Knowledge point learning – from the ground up
Knowledge point review
- input function
- while loop
- Function definition and call
Hands-on programming – hands-on, let the program run
reference code
"""
作者:白菜胡萝丸子
版本V5.0:实现用户决定重复绘制五角星的次数,五角星的大小,填充颜色等
"""
import turtle
# 设置绘制五角星的函数
def pentagram(side_length):
i = 1
while i <= 5:
turtle.forward(side_length)
turtle.right(144)
i = i + 1
# 设置主函数
def main():
# 用户输入五角星的初始边长,重复次数,每重复一次增加的长度
side_length = float(input('您好,请您输入重复五角星的初始边长'))
num = float(input('您好,请您输入准备重复绘制五角星的次数'))
add_side_length = float(input('您好,请您输入每次重复绘制五角星增加的长度:'))
side_color = input('您好,请您输入绘制五角星的边长颜色:')
# 设置五角星的颜色
turtle.pencolor(side_color)
# 设置循环控制变量
order = 1
while order <= num:
pentagram(side_length)
side_length = side_length + add_side_length
order = order + 1
# 点击关闭窗口
turtle.exitonclick()
# 调用主函数
if __name__ == '__main__':
main()
Results of the
Take it to the next level - let the program evolve a little bit
Whether to combine loops and functions into one function (recursive functions), recursive functions are the hill to climb when learning a programming language