Python Forum
Nested Loop to Generate Triangle
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Nested Loop to Generate Triangle
#12
(May-28-2017, 07:25 PM)buran Wrote: so what you have tried, based on my suggestion in post #2? If you expect someone to do this for you - you are mistaken. some examples
n=7 x=4 # example 1 print('{: >{width}s}'.format('O'*x, width=n)) # example 2 print('{}{}'.format(' '*(n-x),'O'*x)) # example 3 print(' '*(n-x), end='') print('O'*x, end='') print()
the last one, which is the worst one can be done with even more loops output
Output:
OOOO OOOO OOOO
Now it's up to you to wrap one of these in a loop
Sorry, but I do wish the picture I had did load correctly. I did try your method and attempted to convert them into my program, but it wasn't what was needed. I did adjust them a bit as well.
Reply


Messages In This Thread
Nested Loop to Generate Triangle - by Babbare - May-25-2017, 04:13 PM
RE: Nested Loop to Generate Triangle - by buran - May-25-2017, 04:45 PM
RE: Nested Loop to Generate Triangle - by nilamo - May-26-2017, 08:39 PM
RE: Nested Loop to Generate Triangle - by nilamo - May-28-2017, 03:17 AM
RE: Nested Loop to Generate Triangle - by buran - May-28-2017, 06:43 AM
RE: Nested Loop to Generate Triangle - by Babbare - May-28-2017, 06:01 PM
RE: Nested Loop to Generate Triangle - by buran - May-28-2017, 07:25 PM
RE: Nested Loop to Generate Triangle - by wavic - May-28-2017, 07:53 PM
RE: Nested Loop to Generate Triangle - by Babbare - May-29-2017, 12:33 AM
RE: Nested Loop to Generate Triangle - by buran - May-29-2017, 05:00 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
Bug Need help on this nested loop task PP9044 4 4,765 Apr-16-2021, 01:31 PM
Last Post: perfringo
  How to write a recursion syntax for Sierpinski triangle using numpy? Bolzano 2 3,992 Apr-03-2021, 06:11 AM
Last Post: SheeppOSU
  Print user input into triangle djtjhokie 1 2,494 Nov-07-2020, 07:01 PM
Last Post: buran
  Tkinter - The Reuleaux Triangle andrewapk 1 2,044 Oct-06-2020, 09:01 PM
Last Post: deanhystad
  Python - networkx - Triangle inequality - Graph Nick_A 0 2,172 Sep-11-2020, 04:29 PM
Last Post: Nick_A
  Triangle function program m8jorp8yne 2 9,028 Dec-13-2019, 05:24 PM
Last Post: Clunk_Head
  Print triangle using while loop tuxandrew 3 5,101 Dec-05-2019, 07:17 PM
Last Post: micseydel
  Nested if stmts in for loop johneven 2 5,990 Oct-19-2019, 04:05 AM
Last Post: xeedon
  Intersection of a triangle and a circle Gira 3 3,722 May-19-2019, 06:04 PM
Last Post: heiner55
  Nested for loop issue always using index 0 searching1 2 2,652 Dec-30-2018, 09:17 AM
Last Post: searching1

Forum Jump:

User Panel Messages

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