Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7606681
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T00:28:14+00:00 2026-05-31T00:28:14+00:00

I have Pascal’s Triangle created however it all prints on one line. Any advice

  • 0

I have Pascal’s Triangle created however it all prints on one line. Any advice how to get it to print in rows (not in triangle shape)?

row=input("Please enter height: ")
triangle=[]
for rownum in range (0,row+1):
   newvalue=1
   newrow=[]
   if row==0:
       newrow.append(int(newvalue))

   elif row==1:
       newrow.append(int(newvalue,newvalue))

   else:

       for column in range(rownum):
         if column==0:
             newrow.append(1)
         elif column==(rownum-1):
             newrow.append(int(newvalue))
         else:
             new_value=triangle[rownum-1][column]+triangle[rownum-1][column-1]
             newrow.append(int(new_value))
   triangle.append(newrow)
print triangle
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T00:28:15+00:00Added an answer on May 31, 2026 at 12:28 am
    >>> print '\n'.join(' '.join(str(n) for n in row) for row in triangle)
    
    1
    1 1
    1 2 1
    1 3 3 1
    1 4 6 4 1
    1 5 10 10 5 1
    

    Alternatively, use str.center to align things nicer:

    >>> print '\n'.join(' '.join(str(n) for n in row).center(80) for row in triangle)
    
                                           1                                        
                                          1 1                                       
                                         1 2 1                                      
                                        1 3 3 1                                     
                                       1 4 6 4 1                                    
                                     1 5 10 10 5 1                                  
    

    To preserve the geometry correctly for larger scales, you could use str.format tricks like this:

    >>> print '\n'.join(' '.join('{:3d}'.format(n) for n in row).center(80) for row in triangle)
    
                                            1                                       
                                          1   1                                     
                                        1   2   1                                   
                                      1   3   3   1                                 
                                    1   4   6   4   1                               
                                  1   5  10  10   5   1                             
                                1   6  15  20  15   6   1                           
                              1   7  21  35  35  21   7   1                         
                            1   8  28  56  70  56  28   8   1                       
                          1   9  36  84 126 126  84  36   9   1                     
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written a function for returning the next row in Pascal's triangle given
I'm a C++-Programmer. But now i have to learn Pascal/Pascal. Are there any websites,
In Turbo Pascal we have the read(); function. Is there a function to get
In Pascal, I have write and writeln . Apparently Lua's print is similar to
After completing an assignment to create Pascal's triangle using an iterative function, I have
We have some ancient Delphi code (might have even originated as Turbo Pascal code)
Have you ever created or encountered a self modifying code in Java? If yes,
I have a pascal code that encrypts files using RIJNDAEL / sha 512 and
I have written a recursive Tree Function in pascal ( or delphi ) but
i need a tool that can convert c/c++ code to delphi(object pascal) code, have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.