Hello everyone, I'm cabbage carrot balls
Life is too short, Python is a song
project import
Version 3.0: The drawing of the five-pointed star is encapsulated into a function, thereby making the program more modular
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
function definition
def <function name> (<parameter list>):
<函数体> return <返回值列表>
function call process
-
The calling program suspends execution at the calling function
-
Assign parameter (actual parameter) to parameter (formal parameter) when calling
-
execute function body
-
Return the execution result, return to the calling place to continue execution
Hands-on programming – hands-on, let the program run
reference code
"""
作者:白菜胡萝丸子
版本3.0:将五角星的绘制封装到函数里,进而使程序更加模块化
"""
import turtle
def pentagram(side_length):
i = 0
while i < 5:
turtle.forward(side_length)
turtle.right(144)
i = i + 1
def main():
turtle.speed(10)
side = 100
pentagram(side)
turtle.exitonclick()
if __name__ == "__main__":
main()
Results of the
Take it to the next level - let the program evolve a little bit
I want to draw more repeated five-pointed stars, change the color of the edges of the five-pointed star, and fill the five-pointed star with color. How to optimize the program?