Problem Set2(Pattern)

Pattern



  1. Given ‘n’, the number of rows, design an algorithm and write a Python code to draw a pattern. If n is ‘5’, the pattern looks as shown below:

**

****

******

********

**********



Input:

Get The Number of Rows as the input and store it in n variable



Processing:

i = 1

while i <=n

print ** i times in a line

i  += 1

Output:

Display The pattern according to the input of n



Algorithm:

Step1. Get the number of rows from the user and store it in n variable.

Step2. initialize i as 1

Step3. Repeat until i less than or equal to n

Step3.1 Print ** i times

Step3.2 increment the value of i by one

Step 4. End

Program:
n = eval(input())
for i in range(1,n+1):
  print('**'*i,end='\n')

Flowchart:



2 comments:

  1. Why do you use double ** instead of *

    ReplyDelete
  2. the question requires us print ** in the first line then **** in the next line if you use * instead of ** then you would get only * in the first line and ** in the second line

    ReplyDelete

Bonus Practice Problems(GMT To IST)

IST (Indian Standard Time) is 5 hours 30 minutes ahead of GMT(Greenwich Mean Time). Develop an algorithm and write the Python code to find...