简体   繁体   中英

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:

  • Importing turtle
  • Making global variables for starting positions
  • turtle stuff (read docs)

Part 2:

  • for loop that runs 8 times
  • turtle pen up (not drawing)
  • start at predefined x position
  • for loop (see Part 3)
  • lower the y position with 60

Part 3:

  • runs a times

  • 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)


**Summary** This program draws 8 lines of circles, and each nth line contains n circles aligned to the right like this:
 * ** *** **** ***** ****** ******* ********

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.

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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