Hello everyone, I'm cabbage carrot balls
Life is too short, Python is a song
project import
Version 2.0: Observe the program code of version V1.0, whether the while loop can be used to make version 1.0 more concise
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
loop statement
- statement of the control program
- The judgment program determines whether a program is executed again one or more times
- Instructions
while(<条件>):
<语句块1>
<语句块2>
- When the condition is true (True), execute statement block 1, when the statement is false (Flase), exit the loop
Hands-on programming – hands-on, let the program run
reference code
"""
作者:白菜胡萝丸子
版本2.0:观察V1.0版本的程序代码,是否能用while循环使版本1.0更加简介
"""
import turtle
def main():
# 设置画笔绘制速度
turtle.speed(2)
# 设置循环的判断条件
i = 0
# 绘制五角星的循环语句
while i < 5:
turtle.forward(100)
turtle.right(144)
i = i + 1
# 设置点击关闭窗口
turtle.exitonclick()
if __name__ == "__main__":
main()
Results of the
Take it to the next level - let the program evolve a little bit
The loop statement greatly simplifies the code of the pentagram, but if you want the program to be more modular, for example, encapsulate the program for drawing the pentagram into a function, and then enter the size of the pentagram to make the program of the pentagram more flexible. Well, let the program evolve a little bit!