Python Forum
Print triangle using while loop
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Print triangle using while loop
#1
The following code will print a triangle of stars.
How we can obtain the same result using while loop? And explain how it works?
Thanks in advance for any help?

l=int(input("Enter the limit:"))
for i in range(1,l+1):
    for j in range(i):
        print("*",end="")
print()
TuxAndrew
Linux - RedHat,cPANEL CentOS,Ubuntu,Azure/AWS Administrator,
Assistance, Analysis and Diagnosis. Skype: tuxandrew,

[email protected]
Reply
#2
What have you tried? We're not big on writing code for people here, but we would be happy to help you fix your code when you run into problems. When you do run into problems, please post your code in Python tags, and clearly explain the problem you are having, including the full text of any errors.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#3
print("Print full Triangle pyramid using stars ")
size = 7
m = (2 * size) - 2
for i in range(0, size):
    for j in range(0, m):
        print(end=" ")
    m = m - 1 # decrementing m after each loop
    for j in range(0, i + 1):
        # printing full Triangle pyramid using stars
        print("* ", end=' ')
    print(" ")
Output:
Print full Triangle pyramid using stars * * * * * * * * * * * * * * * * * * * * * * * * * * * *
Reply
#4
sumana, you seem to have a pattern of providing low-quality answers to posts that haven't necessarily show the effort that you should be giving them as much as you are. This is made worse by things like (1) your code doesn't fulfill the OP's requirement of while loops, so isn't useful and (2) you didn't improve upon the OP's original code, you overcomplicated it.

Please be more mindful, or we may be forced to issue formal warnings and escalate from there.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to write a recursion syntax for Sierpinski triangle using numpy? Bolzano 2 3,805 Apr-03-2021, 06:11 AM
Last Post: SheeppOSU
  Print user input into triangle djtjhokie 1 2,343 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
  Help with for-loop printing. I want it to print only once. blacklight 2 6,866 Jun-26-2020, 02:23 AM
Last Post: pyzyx3qwerty
  Triangle function program m8jorp8yne 2 8,802 Dec-13-2019, 05:24 PM
Last Post: Clunk_Head
  Intersection of a triangle and a circle Gira 3 3,541 May-19-2019, 06:04 PM
Last Post: heiner55
  Program that, inside a loop, does multiple things. needs to print in a certain way reidmcleod 1 2,639 Feb-19-2019, 02:35 PM
Last Post: marienbad
  Draw isosceles triangle fen1c5 4 12,682 Jul-07-2018, 10:20 AM
Last Post: fen1c5
  Pascal's triangle nvakada 5 4,560 May-01-2018, 02:44 AM
Last Post: Skaperen

Forum Jump:

User Panel Messages

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