Python Forum
Nested Loop to Generate Triangle
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Nested Loop to Generate Triangle
#11
In [1]: print('{:x^11}'.format('Y'))
xxxxxYxxxxx
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply
#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
#13
If you want the whole picture you need to put some effort. It's your homework, not ours.
what I gave you are 3 different ways to print one line of the triangle - 4th from the top.
As I said you need to select one of these and put it into loop.
you say that tried to convert them, but it wasn't was needed. Still you don't show code - your best attempt.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Bug Need help on this nested loop task PP9044 4 4,598 Apr-16-2021, 01:31 PM
Last Post: perfringo
  How to write a recursion syntax for Sierpinski triangle using numpy? Bolzano 2 3,804 Apr-03-2021, 06:11 AM
Last Post: SheeppOSU
  Print user input into triangle djtjhokie 1 2,342 Nov-07-2020, 07:01 PM
Last Post: buran
  Tkinter - The Reuleaux Triangle andrewapk 1 1,875 Oct-06-2020, 09:01 PM
Last Post: deanhystad
  Python - networkx - Triangle inequality - Graph Nick_A 0 2,054 Sep-11-2020, 04:29 PM
Last Post: Nick_A
  Triangle function program m8jorp8yne 2 8,797 Dec-13-2019, 05:24 PM
Last Post: Clunk_Head
  Print triangle using while loop tuxandrew 3 4,837 Dec-05-2019, 07:17 PM
Last Post: micseydel
  Nested if stmts in for loop johneven 2 5,836 Oct-19-2019, 04:05 AM
Last Post: xeedon
  Intersection of a triangle and a circle Gira 3 3,535 May-19-2019, 06:04 PM
Last Post: heiner55
  Nested for loop issue always using index 0 searching1 2 2,551 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