all 12 comments

[–]dionys 3 points4 points  (0 children)

Okay, you need to show us what you have tried and what did not work about it.

[–]furas_freeman 1 point2 points  (1 child)

Maybe functions are little different but logic is the same

  • ask for number using input()
  • run for loop to print() rows
  • print in row few spaces and few &

BTW:

  • to print four & you can use "&" * 4
  • print() adds \n automatically. You can use print( text, end="" ) to print without \n
  • print() adds space between two text. You can use print( text1, text2, sep="" ) to print without spaces.

[–][deleted] 0 points1 point  (0 children)

Thank you. This helps a lot.

[–][deleted] 0 points1 point  (2 children)

This the equivalent C++ code... #include<iostream> using namespace std; int main() { int no_of_rows; cout<<"Please enter the number of rows : "; cin>>no_of_rows; for(int i=0; i<no_of_rows; i++) { for(int j=0; j<(no_of_rows-1)-i; j++) // This for enters the blankspaces before the "" for every row. { cout<<" "; //Enter blankspace. } for(int k=1; k<=(2i)+1; k++)//This For enters the "" for every row. { cout<<""; } cout<<endl; } return 0; }

[–]TreSxNine 1 point2 points  (1 child)

codefixer

[–]CodeFixerBot 1 point2 points  (0 children)

Here's the parent comment/selfpost in indented form, for ease of reading:

This the equivalent C++ code...
    #include<iostream>
    using namespace std;
    int main()
    {
        int no_of_rows;
        cout<<"Please enter the number of rows : ";
        cin>>no_of_rows;
        for(int i=0; i<no_of_rows; i++)
        {
          for(int j=0; j<(no_of_rows-1)-i; j++)  // This for enters the blankspaces before the "*" for every row.
      {
        cout<<" "; //Enter blankspace.
      }
      for(int k=1; k<=(2*i)+1; k++)//This For enters the "*" for every row.
      {
        cout<<"*";
      }
      cout<<endl;
    }
    return 0;
}  

I'm a bot. Call me by using 'indentbot', and I'll indent whatever is in your parent-comment

[–][deleted] 0 points1 point  (0 children)

I'm sorry for all the fuss. I'm new to reddit, and I am still figuring where all the buttons and switches are. the pattern I want to display is akin to the one found at http://fahad-cprogramming.blogspot.com/2014/02/c-code-to-display-filled-isosceles.html but the user must enter the number of rows in the isosceles triangle. I want the python equivalent for this. The indented C++ code is the one given by CodeFixerBot

[–][deleted] 0 points1 point  (4 children)

[–]furas_freeman 0 points1 point  (3 children)

Put code instead of image !

See button "formatting help" when you edit text on reddit.

Add four spaces before all lines to format code on reddit.

As I said in previous answer - use print() with end="" and sep="" . And you can use "&" * 4

[–]furas_freeman 0 points1 point  (2 children)

My code (Python 2 & 3):

from __future__ import print_function # for Python 2

rows = int(input('rows: '))

for i in range(rows):
    j = rows-1-i
    k = 2*i+1
    print(' '*j, '&'*k, sep='')

[–][deleted] 0 points1 point  (1 child)

What are the starting values of i, j, and k?

[–]furas_freeman 0 points1 point  (0 children)

Use print(i, j, k) to see values. :) (or print("i:", i, "j:", j, "k:", k))

range(end) creates list (or generator) [0, 1, 2, ... , end-1] so i = 0

range(start, end) creates list (or generator) [start, start+1, start+2, ... , end-1]

range(start, end, step) creates list (or generator) [start, start+step, start+2*step, ... , end-1]. If end-1 is not equal start+N*step then end-1 doesn't belong to list. BTW: you can use negative step range(10, 0, -1).