Python Forum
Printing out a triangle using nested for loops
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Printing out a triangle using nested for loops
#2
You are going to need a loop. Either a for loop or a while loop would do. You'll need a condtional (if/else) to decide when to start subtracting from the loop index (for loop) or decrementing instead of incrementing the loop index you are keeping track of your self (while) loop. Note that '*' * 3 = '***'. Once you have the right index, you'll need that to display the diamond.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply


Messages In This Thread
RE: Printing out a diamond - by ichabod801 - Jan-15-2019, 04:34 PM
RE: Printing out a diamond - by Larz60+ - Jan-15-2019, 05:30 PM
RE: Printing out a diamond - by ichabod801 - Jan-15-2019, 07:04 PM
RE: Printing out a diamond - by Larz60+ - Jan-15-2019, 07:20 PM
RE: Printing out a diamond - by MrGoat - Jan-15-2019, 09:48 PM
RE: Printing out a diamond - by ichabod801 - Jan-15-2019, 10:01 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  reduce nested for-loops Phaze90 11 2,016 Mar-16-2023, 06:28 PM
Last Post: ndc85430
Sad triangle numbers Woody_MC_2022 5 1,285 Sep-24-2022, 08:14 PM
Last Post: deanhystad
  Nested for loops: Iterating over columns of a DataFrame to plot on subplots dm222 0 1,762 Aug-19-2022, 11:07 AM
Last Post: dm222
  Nested for loops - help with iterating a variable outside of the main loop dm222 4 1,683 Aug-17-2022, 10:17 PM
Last Post: deanhystad
  breaking out of nested loops Skaperen 3 1,285 Jul-18-2022, 12:59 AM
Last Post: Skaperen
  Break out of nested loops muzikman 11 3,493 Sep-18-2021, 12:59 PM
Last Post: muzikman
  How to break out of nested loops pace 11 5,514 Mar-03-2021, 06:25 PM
Last Post: pace
  Nested for Loops sammay 1 9,814 Jan-09-2021, 06:48 PM
Last Post: deanhystad
  How to make this function general to create binary numbers? (many nested for loops) dospina 4 4,529 Jun-24-2020, 04:05 AM
Last Post: deanhystad
  Python beginner - nested while loops mikebarden 1 1,912 Jun-01-2020, 01:04 PM
Last Post: DPaul

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020