简体   繁体   English

流程图嵌套for循环

[英]Flowchart nested for-loop

I have this code and I tried to do a flowchart but I have no clue how to make one.我有这段代码,我试图做一个流程图,但我不知道如何制作一个。 All of my Flowchart I made, don't make any sense.我制作的所有流程图都没有任何意义。

Could anyone of you guys please help me out???有谁能帮帮我吗???

import turtle

STARTING_X, STARTING_Y = 350, 200

turtle.penup()
turtle.width(2)
turtle.setheading(180)
turtle.sety(STARTING_Y)

for a in range(1, 8):
    turtle.penup()
    turtle.setx(STARTING_X)

    for b in range(a):
        turtle.pendown()
        turtle.circle(25)
        turtle.penup()
        turtle.forward(60)

    turtle.sety(turtle.ycor() - 60)

turtle.done()

The code:编码:

# part 1
import turtle
STARTING_X, STARTING_Y = 350, 200
turtle.penup()
turtle.width(2)
turtle.setheading(180)
turtle.sety(STARTING_Y)

# part 2
for a in range(1, 8):
    turtle.penup()
    turtle.setx(STARTING_X)

    for b in range(a):    # part 3
        turtle.pendown()
        turtle.circle(25)
        turtle.penup()
        turtle.forward(60)

    turtle.sety(turtle.ycor() - 60)

turtle.done()

Part 1:第1部分:

  • Importing turtle进口乌龟
  • Making global variables for starting positions为起始位置制作全局变量
  • turtle stuff (read docs)海龟的东西(阅读文档)

Part 2:第2部分:

  • for loop that runs 8 times运行 8 次的 for 循环
  • turtle pen up (not drawing)乌龟笔起来(不画)
  • start at predefined x position从预定义的 x position 开始
  • for loop (see Part 3) for 循环(参见第 3 部分)
  • lower the y position with 60将 y position 降低 60

Part 3:第 3 部分:

  • runs a timesa一次

  • turtle pendown (drawing)乌龟笔下(绘图)

  • drawing a circle画一个圆圈

  • turtle penup (not drawing)乌龟笔(不画)

  • go forward with 60 (in this case, lower the x position with 60 because of the direction in part 1) go 向前 60(在这种情况下,由于第 1 部分中的方向,将 x position 降低 60)


**Summary** This program draws 8 lines of circles, and each nth line contains n circles aligned to the right like this: **总结**这个程序画了8行圆,每n行包含n个向右对齐的圆,如下所示:
 * ** *** **** ***** ****** ******* ********

But circles instead of stars但是圆圈而不是星星

First of all thank you very much for your help:)首先非常感谢您的帮助:)

But my question now is how to put that information into a flowchart like this.但我现在的问题是如何将这些信息放入这样的流程图中。 I mean what's the Condition 1 / 2, what are the statements etc.我的意思是条件 1 / 2 是什么,语句是什么等。

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM