Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
print a * pyramid
#6
Here's my way of solving the problem. Since unlike C, printing str/int is directly concatenated after the loop, while in Python, the string is printed in newline. To solve this, i just created an output string "star" and then appended all the necessary data created by the loop.
row = int(input("Input the number of rows of your pyramid: "))
j = int()
k = int()
s = int()
star = str()
for j in range(1, row + 1):
    for s in range(row - j,0, -1):
        star += str(" ")
    for k in range(0, 2*j - 1):
        star +=str("*")
    star += str("\n")
print(star)
Reply


Messages In This Thread
print a * pyramid - by drogers10940 - Oct-23-2017, 04:16 PM
RE: print a * pyramid - by sparkz_alot - Oct-23-2017, 08:29 PM
RE: print a * pyramid - by drogers10940 - Oct-23-2017, 10:54 PM
RE: print a * pyramid - by drogers10940 - Oct-24-2017, 01:34 PM
RE: print a * pyramid - by gruntfutuk - Oct-27-2017, 08:33 PM
RE: print a * pyramid - by prothej227 - Apr-26-2020, 09:25 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Pyramid of leters of n levels DanyMont1505 4 2,262 Sep-27-2019, 07:56 PM
Last Post: woooee
  Pyramid gamingingrs 1 2,333 Oct-16-2018, 02:56 PM
Last Post: j.crater
  Pyramid of Solitaires qwerty 1 3,529 Mar-22-2017, 04:10 PM
Last Post: nilamo
  Implementation Pyramid Solitaire qwerty 2 5,159 Feb-27-2017, 11:57 AM
Last Post: qwerty

Forum Jump:

User Panel Messages

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