Bifalgorithm post

right, triangle pattern, and left triangle pattern. You can print both of these patterns with just two lines of code. First, the right triangle. We print stars based on the row number. So the first row has one star, the second has two, and so on. We can write for I in a range of one comma six, and print star multiplied by I. When we run it, we get our right triangle. But now, how do we move the stars to the right? Because we are adding spaces before them. In the first row, we add four spaces and one star. In the second row, three spaces and two stars, and so on. So we write for i in a range of and print space multiplied by 5 minus i plus star multiplied by i. As the number of spaces decreases, the stars move toward the right, giving us the left triangle.

right, triangle pattern, and left triangle pattern. You can print both of these patterns with just two lines of code. First, the right triangle. We print stars…

Ideas in this flowchart

  • Triangle Pattern Printing
  • Right Triangle Pattern
  • Left Triangle Pattern
  • Print Stars by Row Number
  • For Loop: range(1, 6)
  • Print: '*' * i
  • Add Spaces Before Stars
  • Print: ' ' * (5 - i) + '*' * i
Feed/

right, triangle pattern, and left triangle pattern. You can print both of these patterns with just two lines of code. First, the right triangle. We print stars based on the row number. So the first row has one star, the second has two, and so on. We can write for I in a range of one comma six, and print star multiplied by I. When we run it, we get our right triangle. But now, how do we move the stars to the right? Because we are adding spaces before them. In the first row, we add four spaces and one star. In the second row, three spaces and two stars, and so on. So we write for i in a range of and print space multiplied by 5 minus i plus star multiplied by i. As the number of spaces decreases, the stars move toward the right, giving us the left triangle.

"right, triangle pattern, and left triangle pattern."

👍
0
0 comments0 shares

Sign in to view and post comments.