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

  • Home
  • SEARCH
  • 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 9062137
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T15:39:43+00:00 2026-06-16T15:39:43+00:00

I would like to ask again the help of the Python experts in this

  • 0

I would like to ask again the help of the Python experts in this forum. The task is to create a program that will return a triangle pattern. However, there must be a siblings.

Sample input:

Input an Integer:
9

Sample Output:

*
**
***
****      *
*****     **
******    ***
*******   ****   *
********  *****  **
********* ****** ***

The code that I have so far is:

a = int(input("Input a number? "))

k=a/3
t=a-k
y=a-(k*2)

for i in range(a + 1):
    print '*' * i

for i in range(t + 1):
    print '*' * i

for i in range(y + 1):
    print '*' * i

When I run this code the output is:

Input a number: 12
*
**
***
****
*****   
******
*******
********
*********
**********
***********
************

*
**
***
****
*****   
******
*******
********

*
**
***
****

It prints after the first triangle, my goal is to print it beside each 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-06-16T15:39:45+00:00Added an answer on June 16, 2026 at 3:39 pm

    makes your triangles.

    def make_triangle(size, siblings, step): 
        return [['*' * (i-(step*sib)) + ' ' * ((size-(step*sib)) - ((i-(step*sib)) if (i-(step*sib) > 0) else 0)) for sib in xrange(siblings)] for i in xrange(1, size+1)]
    

    output:

    >>> for i in make_triangle(9,3,3):
        print ''.join(i)
    
    
    *                        
    **                     
    ***                  
    ****     *          
    *****    **        
    ******   ***      
    *******  ****  *  
    ******** ***** ** 
    ******************
    

    or you could keep it all in the function and:

    def make_triangle(size, siblings, step): 
        return '\n'.join([''.join(line) for line in [['*' * (i-(step*sib)) + ' ' * ((size-(step*sib)) - ((i-(step*sib)) if (i-(step*sib) > 0) else 0)) for sib in xrange(siblings)] for i in xrange(1, size+1)]])
    
    >>> print make_triangle(9,3,3)
    *                        
    **                     
    ***                  
    ****     *          
    *****    **        
    ******   ***      
    *******  ****  *  
    ******** ***** ** 
    ******************
    

    and if you want a space between them:

    def make_triangle(size, siblings, step): 
        return '\n'.join([' '.join(line) for line in [['*' * (i-(step*sib)) + ' ' * ((size-(step*sib)) - ((i-(step*sib)) if (i-(step*sib) > 0) else 0)) for sib in xrange(siblings)] for i in xrange(1, size+1)]])
    
    >>> print make_triangle(9,3,3)
    *                          
    **                       
    ***                    
    ****      *           
    *****     **         
    ******    ***       
    *******   ****   *  
    ********  *****  ** 
    ********* ****** ***
    

    for fun (and you can see very nice function):

    >>> print make_triangle(13,5,2)
    *                                                                
    **                                                           
    ***           *                                           
    ****          **                                       
    *****         ***         *                          
    ******        ****        **                       
    *******       *****       ***       *             
    ********      ******      ****      **           
    *********     *******     *****     ***     *    
    **********    ********    ******    ****    **   
    ***********   *********   *******   *****   ***  
    ************  **********  ********  ******  **** 
    ************* *********** ********* ******* *****
    

    and more fun:

    >>> print make_triangle(13,5,2)[::-1]
    ***** ******* ********* *********** *************
     ****  ******  ********  **********  ************
      ***   *****   *******   *********   ***********
       **    ****    ******    ********    **********
        *     ***     *****     *******     *********
               **      ****      ******      ********
                *       ***       *****       *******
                         **        ****        ******
                          *         ***         *****
                                     **          ****
                                      *           ***
                                                   **
                                                    *
    

    addition: some explanation of how it works:

    this is what the code does in more basic form:

    def make_triangle(size, siblings, step): 
        out_list = []
        for i in xrange(1, size+1):
            in_list = []
            for sib in xrange(siblings):
                if i-(step*sib) > 0: 
                    in_list.append('*' * (i-(step*sib)) + ' ' * ((size-(step*sib)) - (i-(step*sib))))
                else:
                    in_list.append('*' * (i-(step*sib)) + ' ' * (size-(step*sib))
            out_list.append(in_list)
        line_list = []
        for in_list in out_list:
            line_list.append(' '.join(in_list))
        result = '\n'.join(line_list)
        return result
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to create something like CameraCaptureUI.CaptureFileAsync which will return the result to
I would like to ask you: Imagine that you have a site and there
After Google-ing the whole day, I will have to ask experts to help me.
I would like ask if there's a way to download an android layout from
What I would like ask is best illustrated by an example, so bear with
I would like to ask such question, I have XML xsd`s, which generate beans
I would like to ask, how can I define class inside another one. In
I would like to ask you about regular expressions preg_match have outlined below. I
i would like to ask a question about @UsesJAXBContext annotation in jax-ws. I try
I would like to ask for more an opinion than a question: What would

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.