This Python lesson includes over 35+ coding programs for printing Numbers, Pyramids, Stars, triangles, Diamonds, and alphabet patterns, ensuring you gain hands-on experience and confidence in your Python skills.
Printing numbers, stars (asterisk), or other characters in different shapes (patterns) is a frequently asked interview question for freshers. Creating these number and pyramid patterns allows you to test your logical ability and coding skills.
In this lesson, you’ll learn how to print patterns using the for loop, while loop, and the range() function.
This article teaches you how to print the following patterns in Python.
- Number pattern
- Pyramid pattern
- Inverted pyramid pattern
- Half pyramid pattern
- Triangle pattern
- Star (*) or asterisk pattern
- Diamond Shaped pattern
- Characters or alphabet pattern
- Square pattern

Table of contents
- Steps to Print Pattern in Python
- Number Patterns Programs In Python
- Pyramid pattern of numbers
- Inverted pyramid pattern of numbers
- Inverted Pyramid pattern with the same digit
- Another inverted half-pyramid pattern with a number
- Alternate numbers pattern using a while loop
- Reverse number pattern
- Reverse Pyramid of Numbers
- Another reverse number pattern
- Print reverse number from 10 to 1
- Number triangle pattern
- Pascal’s triangle pattern using numbers
- Square pattern with numbers
- Multiplication table pattern
- Pyramid pattern of stars in python
- Right triangle pyramid of Stars
- Downward half-Pyramid Pattern of Star
- Downward full Pyramid Pattern of star
- Right down mirror star Pattern
- Equilateral triangle pattern of star
- Print two pyramids of stars
- Right start pattern of star
- Left triangle pascal’s pattern
- Sandglass pattern of star
- Pant style pattern of stars
- Diamond-shaped pattern of stars
- Alphabets and letters pattern
- More miscellaneous Patterns
- Pyramid of horizontal number tables
- Double the number pattern
- Random number pattern
- Pyramid of numbers less than 10
- Pyramid of numbers up to 10
- Even number pattern
- Unique pyramid pattern of digits
- Pattern double number on each column
- Number reduction pattern
- Pant style pattern of numbers
- Pattern with a combination of numbers and stars
- Practice Problem
- Next Steps
Steps to Print Pattern in Python
To print any pattern, you must first understand its logic and technique. Use the below steps to print any pattern in Python.
- Decide the number of rows and columns
The number of rows and columns is crucial when printing a pattern. To achieve this, we utilize two loops: outer loops and nested loops. The outer loop is the number of rows, while the inner loop tells us the column needed to print the pattern.
The input () function accepts the number of rows from a user to decide the size of a pattern. - Iterate rows
Next, write an outer loop to Iterate the number of rows using a for loop and
range()function. - Iterate columns
Next, write the inner or nested loop to handle the number of columns. The internal loop iteration depends on the values of the outer loop.
- Print star or number
Use the
print()function in each iteration of nestedforloop to display the symbol or number of a pattern (like a star (asterisk*) or number). - Add a new line after each iteration of the outer loop
Add a new line using the
print()function after each iteration of the outer loop so that the pattern displays appropriately

Also, Solve:
Number Patterns Programs In Python
I have created various programs that print different styles of number patterns. Let’s see them one by one. Let’s print the following number pattern using a for loop.
1 2 2 3 3 3 4 4 4 4 5 5 5 5 5
Program:
In this number pattern, we display a single digit on the first row, two digits on the second row, and three digits on the third row. This process will repeat until the number of rows is reached.
Note:
- The count of numbers on each row is equal to the current row number.
- Also, each number is separated by space.
- We used a nested loop to print the pattern
Pyramid pattern of numbers
Let’s see how to print the following half-pyramid pattern of numbers
1 1 2 1 2 3 1 2 3 4 1 2 3 4 5
Note: In each row, every next number is incremented by 1.
Program:
Inverted pyramid pattern of numbers
An inverted pyramid is a downward pattern where numbers get reduced in each iteration, and on the last row, it shows only one number. Use reverse for loop to print this pattern.
Pattern
1 1 1 1 1 2 2 2 2 3 3 3 4 4 5
Program
Inverted Pyramid pattern with the same digit
Pattern: –
5 5 5 5 5 5 5 5 5 5 5 5 5 5 5
Program: –
Another inverted half-pyramid pattern with a number
Pattern: –
0 1 2 3 4 5 0 1 2 3 4 0 1 2 3 0 1 2 0 1
Program
Alternate numbers pattern using a while loop
Let’s see how to use the while loop to print the number pattern.
Pattern: –
1 3 3 5 5 5 7 7 7 7 9 9 9 9 9
Program: –
Reverse number pattern
Let’s see how to display the pattern of descending order of numbers
Pattern 1: –
5 5 5 5 5 4 4 4 4 3 3 3 2 2 1
This pattern is also called as a inverted pyramid of descending numbers.
Program: –
Reverse Pyramid of Numbers
Pattern 2: –
1 2 1 3 2 1 4 3 2 1 5 4 3 2 1
Note: It is a downward increment pattern where numbers get increased in each iteration. At each row, the amount of number is equal to the current row number.
Program
Another reverse number pattern
Pattern: –
5 4 3 2 1 4 3 2 1 3 2 1 2 1 1
Program: –
Print reverse number from 10 to 1
Pattern: –
1 3 2 6 5 4 10 9 8 7
Program: –
Number triangle pattern
Let’s see how to print the right-angled triangle pattern of numbers
Pattern: –
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
Program: –
Pascal’s triangle pattern using numbers
To build the pascal triangle, start with “1” at the top, then continue placing numbers below it in a triangular pattern.
Each number is the numbers directly above it added together.
Pattern:
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
Program: –
Square pattern with numbers
Pattern: –
1 2 3 4 5 2 2 3 4 5 3 3 3 4 5 4 4 4 4 5 5 5 5 5 5
Program: –
Multiplication table pattern
Pattern: –
1 2 4 3 6 9 4 8 12 16 5 10 15 20 25 6 12 18 24 30 36 7 14 21 28 35 42 49 8 16 24 32 40 48 56 64
Program: –
Pyramid pattern of stars in python
This section will see how to print pyramid and Star (asterisk) patterns in Python. Here we will print the following pyramid pattern with Star (asterisk).
- Half pyramid pattern with stars(*)
- Full pyramid pattern with stars
- Inverted pyramid Pattern with stars
- Triangle pattern with stars
- Right-angled triangle pattern with stars
Simple half pyramid pattern: –
* * * * * * * * * * * * * * *
This pattern is also known as a right angle triangle pyramid.
Program: –
Right triangle pyramid of Stars
Pattern: –
*
* *
* * *
* * * *
* * * * *
This pattern is also called as mirrored right triangle
Program: –
Alternative Solution:
Downward half-Pyramid Pattern of Star
Pattern: –
* * * * * * * * * * * * * * *
Note: We need to use the reverse nested loop to print the downward pyramid pattern of stars
Program: –
Downward full Pyramid Pattern of star
Let’s see how to print reversed pyramid pattern in Python.
Pattern: –
* * * * * *
* * * * *
* * * *
* * *
* *
*
Program:
Right down mirror star Pattern
Pattern: –
*****
****
***
**
*
In this pattern, we need to use two nested while loops.
Program: –
Equilateral triangle pattern of star
Pattern: –
*
* *
* * *
* * * *
* * * * *
* * * * * *
* * * * * * *
Program: –
Print two pyramids of stars
Pattern: –
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
Program: –
Right start pattern of star
Pattern: –
* * * * * * * * * * * * * * * * * * * * * * * * *
We also call this pattern as a right pascal’s triangle.
Program: –
Left triangle pascal’s pattern
Pattern: –
*
* *
* * *
* * * *
* * * * *
* * * *
* * *
* *
*
Program: –
Sandglass pattern of star
Pattern: –
* * * * *
* * * *
* * *
* *
*
*
* *
* * *
* * * *
* * * * *
To print this pattern we need to use two set of three while loops.
Program: –
Pant style pattern of stars
Pattern: –
**************** *******__******* ******____****** *****______***** ****________**** ***__________*** **____________** *______________*
Program: –
Diamond-shaped pattern of stars
Pattern: –
*
* *
* * *
* * * *
* * * * *
* * * * * *
* * * * *
* * * *
* * *
* *
*
Program: –
Another diamond pattern of star
Pattern: –
*
* *
* *
* *
* *
* *
* *
* *
*
Program: –
Alphabets and letters pattern
In Python, there are ASCII values for each letter. To print the patterns of letters and alphabets, we need to convert them to their ASCII values.
- Decide the number of rows
- Start with ASCII number 65 ( ‘A’)
- Iterate a loop and in nested
forloop use thecharfunction to convert ASCII number to its equivalent letter.
Let’ see now how to print alphabets and letters patterns in Python.
Pattern: –
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z [ \
This pattern is knows as right-angled pattern with characters.
Program: –
Pattern to display letter of the word
Let’s see how to print word ‘Python’ in Pattern: –
P Py Pyt Pyth Pytho Python
Program: –
Equilateral triangle pattern of characters/alphabets
Pattern: –
A
B C
D E F
G H I J
K L M N O
P Q R S T U
V W X Y Z [ \
Program: –
Pattern of same character
Pattern: –
V V V V V V V V V V V V V V V
Program: –
Let’s see some more miscellaneous patterns
More miscellaneous Patterns
Pyramid of horizontal number tables
Pattern: –
1 2 4 3 6 9 4 8 12 16 5 10 15 20 25 6 12 18 24 30 36 7 14 21 28 35 42 49 8 16 24 32 40 48 56 64 9 18 27 36 45 54 63 72 81 10 20 30 40 50 60 70 80 90 100
Program: –
Double the number pattern
Pattern: –
1 2 1 4 2 1 8 4 2 1 16 8 4 2 1 32 16 8 4 2 1 64 32 16 8 4 2 1 128 64 32 16 8 4 2 1
Note: In each column, every number is double it’s the preceding number.
Program: –
Random number pattern
1 1 2 1 1 2 4 2 1 1 2 4 8 4 2 1 1 2 4 8 16 8 4 2 1 1 2 4 8 16 32 16 8 4 2 1 1 2 4 8 16 32 64 32 16 8 4 2 1 1 2 4 8 16 32 64 128 64 32 16 8 4 2 1
Program: –
Pyramid of numbers less than 10
Pattern: –
1 2 3 4 5 6 7 8 9
Program: –
Pyramid of numbers up to 10
Pattern: –
1 2 3 4 5 6 7 8 9 10
Program: –
Even number pattern
Pattern: –
10 10 8 10 8 6 10 8 6 4 10 8 6 4 2
Programs: –
Unique pyramid pattern of digits
Pattern: –
1 1 2 1 1 2 3 2 1 1 2 3 4 3 2 1 1 2 3 4 5 4 3 2 1
Program: –
Pattern double number on each column
Pattern: –
0 0 1 0 2 4 0 3 6 9 0 4 8 12 16 0 5 10 15 20 25 0 6 12 18 24 30 36
Program: –
Number reduction pattern
Pattern: –
1 2 3 4 5 2 3 4 5 3 4 5 4 5 5
Program: –
Pant style pattern of numbers
Pattern: –
5 4 3 2 1 1 2 3 4 5 5 4 3 2 2 3 4 5 5 4 3 3 4 5 5 4 4 5 5 5
Program: –
Pattern with a combination of numbers and stars
Pattern: –
1 * 2 * 3 * 4 1 * 2 * 3 1 * 2 1
Program: –
Also, see how to calculate the sum and average in Python.
Practice Problem
Pattern: –
0 2 4 4 8 8 8 16 16 16
Solution: –
Next Steps
Solve:
If you don’t find the pattern you are looking for, let me know by leaving a comment and questions below.

“”” places you need to enter “””
z = “-”
y = “|” # vertical_character
x = “_” # horinzontal_character
roof = 3 # roof_length
word = “recepdeniz”
“”” ************************ “””
word = f”{z}”.join(word)
sag = y+x
sol = x+y
w_index = 0
print(” ” * ((roof * 2)-1) , f”{x}” * 3)
for i in range(1, roof+1):
print(” ” * (2*(roof-i)) ,sol ,sag * (i-1) ,f”|{word[i-1]}|”, sol * (i-1), sag, sep=””)
w_index += 1
for j in range(1, (len(word) – (roof-1))):
print(sag * roof ,f”|{word[w_index]}|”, sol * roof, sep=””)
w_index += 1
for l in range(1):
print(f”{y}”, f”{x}” * ((roof * 5) – (roof-1)), f”{y}”, sep=””)
# output —>
___
_||r||_
_||_|-|_||_
_||_|_|e|_|_||_
|_|_|_|-|_|_|_|
|_|_|_|c|_|_|_|
|_|_|_|-|_|_|_|
|_|_|_|e|_|_|_|
|_|_|_|-|_|_|_|
|_|_|_|p|_|_|_|
|_|_|_|-|_|_|_|
|_|_|_|d|_|_|_|
|_|_|_|-|_|_|_|
|_|_|_|e|_|_|_|
|_|_|_|-|_|_|_|
|_|_|_|n|_|_|_|
|_|_|_|-|_|_|_|
|_|_|_|i|_|_|_|
|_|_|_|-|_|_|_|
|_|_|_|z|_|_|_|
|_____________|
this code output is looking bad on this comment
WAP to print the given pattern:
1,9,25,49,81
1,9,25,49
1,9,25
1,9
1
for loop in range(6,1,-1):
n=1
for i in range(loop-1):
print(n*n,end=” “)
n+=2
print(“\n”)
How to print
123
654
789
121110
Please WAP to print the given pattern:
1,9,25,49,81
1,9,25,49
1,9,25
1,9
1
n=5
star=n
for i in range(1,n+1):
for j in range(1,star*2,2):
print(j*j,”,end=”)
print()
star-=1
1 2 3
1 2 3 1 2 3
1 2 3 1 2 3 1 2 3
If n=3
for loop in range(1,4):
for i in range(loop):
print(“1 2 3″,end=” “)
print(“\n”)
HA HA HA
1 1
1 2 2 1
1 2 3 3 2 1
1 2 3 4 4 3 2 1
1 2 3 4 5 5 4 3 2 1
code:-
n=int(input())
for i in range(1,n+1):
for j in range(1,i+1):
print(j,end=” “)
for j in range(2*(n-i)):
print(” “,end=” “)
for j in range(i,0,-1):
print(j,end=” “)
print()
n = 5
for i in range(1,n+1):
for j in range(1,i+1):
print(j,end=’ ‘)
for j in range(i,0,-1):
print(j,end=’ ‘)
print()
this is easy I thing what your opinion
Please give an algorithm for two pyramid star pattern using nested loop
E
D E
C D E
B C D E
A B C D E
n=5
start_char=ord(“A”)
for i in range(n,0,-1):
for j in range(n-1):
print(” “,end=” “)
for j in range(i,n+1):
print(chr(start_char+j-1),end=” “)
print()
n=int(input(“Enter the number of rows :”)
for i in range(1,n+1):
for j in range((n+1-i),(n+1)):
print(chr(64+j),end=” “)
print()
rows = int(input(“enter the number of rows: “))
for i in range(1, rows + 1):
for j in range(1, i + 1):
print(i * j, end=’ ‘)
print()
Please write code for this pattern in python:
#.#.#.#.#.#.#.#.#
#.#.#.#…#.#.#.#
#.#.#………..#.#.#
#.#……………..#.#
#…………………#
#.#……………..#.#
#.#.#……….#.#.#
#.#.#.#…#.#.#.#
#.#.#.#.#.#.#.#.#
I did get the output like this . Here is the Code . Hope it Helps
for i in range(1,5):
for j in range(5-i):
if j%2 == 0:
print(‘#’,end=” “)
else:
print(‘.’,end=” “)
for j in range(2*i-1):
if i == 1:
print(‘#’,end=” “)
else:
print(‘.’,end=” “)
for j in range(5-i,0,-1):
if j%2 == 0:
print(‘.’,end=” “)
else:
print(‘#’,end=” “)
print()
for i in range(3,0,-1):
for j in range(5-i):
if j%2 == 0:
print(‘#’,end=” “)
else:
print(‘.’,end=” “)
for j in range(2*i-1):
if i == 1:
print(‘#’,end=” “)
else:
print(‘.’,end=” “)
for j in range(5-i,0,-1):
if j%2 == 0:
print(‘.’,end=” “)
else:
print(‘#’,end=” “)
print()
Sorry I couldn’t find the box to leave my question there so I replied to this comment
I wanna print out in this form
3
5
7
I don’t know where I am doing wrong that my codes don’t work at all
I’ll appreciate if you answer
Actually the form is not like this, I typed in the correct form don’t know why got like this
It must be like this imagine these numbers as a square
1 2 3
4 5 6
7 8 9
Imagine all of these numbers printed in the shape of a square and only the numbers (3, 5, 7) must be printed in the form that they are placed in a square
Here is the answer
count = 1
for i in range(1,4):
for j in range(1,4):
if i + j == 4:
print(count,end=” “)
else:
print(‘ ‘,end=” “)
count += 1
print()
5 5 5 5 5
4 5 5 5 5
3 4 5 5 5
2 3 4 5 5
1 2 3 4 5
I want this as output.
row =5
num = row
for i in range(1,row+1):
for j in range(row):
print(num,end=” “)
if(num<row):
num+=1
num =row-i
print("")
n=int(input());
for i in range (0,n):
for j in range (0,i+1):
print(n-j,end=’ ‘)
for j in range (0,n-i-1):
print(n,end=’ ‘)
print();
for loop in range(1,6):
a=6-loop
for i in range(loop):
print(i+a,end=” “)
for j in range(5,loop,-1):
print(“5″,end=” “)
print(“\n”)
1
2 2 2
3 3 3 3 3
4 4 4 4 4 4 4
5 5 5 5 5 5 5 5 5
a=int(input())
b=1
for i in range(1,a+a,2):
for j in range(i):
print(b,end=” “)
b+=1
print()
b = 0
rows = 10
for i in range(1,rows,2):
b += 1
for j in range(i):
print(b,end=” “)
print()
b=1
for loop in range(1,6):
print(f”{loop}”*b, end=’ ‘)
print(“\n”)
b+=2
s = 3 n= 4write a program to print a inverted hollow pyramid of n rows using numbers starting from scount = 3
for i in range(4,0,-1):
for j in range(4-i):
print(‘ ‘,end=” “)
for j in range(2*i-1):
if j== 0 or j == 2*i-2:
print(count+j,end=” “)
else:
print(‘ ‘,end=” “)
print()
1. 2 2 2 2
1. 1. 2. 2. 2
1. 1. 1. 2. 2
1. 1. 1. 1. 2
Can someone please solve this
can someone please solve this
1
1 2
3 2 1
1 2 3 4
5 4 3 2 1
Yes good question
And the answer is
n=5
for i in range(1,n+1):
if i%2==0:
for j in range(1,i+1):
print(j,end=’ ‘)
print()
else:
for j in range(i,0,-1):
print(j,end=’ ‘)
print()
for loop in range(1,6):
if loop%2==0:
for i in range(1,loop+1):
print(i,end=” “)
print(“\n”)
else:
for i in range(loop,0,-1):
print(i,end=” “)
print(“\n”)
for loop in range(1,6):
if loop%2==0:
for i in range(1,loop+1):
print(i,end=” “)
print(“\n”)
else:
for i in range(loop,0,-1):
print(i,end=” “)
print(“\n”)
2. input=5
OUTPUT:
13 2
4 5 6
10 9 8 7
i need a code for this
num = int(input("enter the number:"))c = 1
for i in range(num):
if i % 2 == 0:
for j in range(i + 1):
print(c, end=" ")
c += 1
else:
start_num = c + i
for j in range(i + 1):
print(start_num, end=" ")
start_num -= 1
c += 1
print()
n=int(input())c=1
for i in range(1,n+1):
string=""
for j in range(1,i+1):
string=str(c)+" "+string
c+=1
print(string)
sorry for the above code mistake in j loop. this is actual code and simple way…….
n=int(input())c=1
for i in range(1,n+1):
string=””
for j in range(i+1,1,-1):
string=str(c)+” “+string
c+=1
print(string)
I need a code for the below pattern..plz help me
A P Q R
A B Q R
A B C R
A B C D
str1 = "ABCD"str2 = "PQR"
for i in range(4):
print(str1[0:i+1] + str2[i:]
I have simpler code for
Your code
Unique pyramid pattern of digits
Pattern: –
1
1 2 1
1 2 3 2 1
1 2 3 4 3 2 1
1 2 3 4 5 4 3 2 1
Program: –
rows = 6for i in range(1, rows + 1):
for j in range(1, i - 1):
print(j, end=" ")
for j in range(i - 1, 0, -1):
print(j, end=" ")
print()
my code
rows = 6a = 1
for i in range(1, rows + 1):
for j in range(1, i - 1):
print(j, end=" ")
print(a**2)
a = (a*10)+1
the series you wrote goes like this
1
(11)^2
(111)^3
.
I hope my suggestion is valuable
thanks!!
S
AS
IAS
AS
S
Code plz…yah…
s='IAS'for i in range(3):
for j in range(i+1):
print(s[j+2-i] , end=' ')
print()
for i in range(1):
for j in range(2-i):
print(s[j+1] , end=' ')
print()
print(s[2])
for loop in range(1,6):
for i in range(1,loop):
print(i,end=” “)
for j in range(loop):
print(loop-j,end=” “)
print(“\n”)
1
2 2 2
3 3 3 3 3
for i in range(3):for j in range(2*i+1):
print( str(i+1) , end=' ')
print()
i wrote dynamic format , user want’s to give any nymber…..
n=int(input())c=1
for i in range(1,n+1):
for j in range(1,i*2):
print(str(c)+" ",end="")
print(" ")
c+=1
1******
12*****
123****
1234***
12345**
123456*
1234567
n=7
for loop in range(1,9):
for i in range(1,loop):
print(i,end=” “)
print(“*”*n,end=” “)
n-=1
print(“\n”)
But it is also printing 8 “*” on top of the pyramid. please reply to remove it. else, the pattern is as is.
n=7
for loop in range(1,9):
for i in range(1,loop):
print(i,end=” “)
print(“*”*n,end=” “)
n-=1
print(“\n”)
But it is also printing 8 “*” on top of the pyramid. please reply to remove it. else, the pattern is as is.
If n = 5
e
e
e
e
e@@@@@
e @@@
e @
e
e
Please write code for this program.
1
2 7
3 8 13
4 9 14 19
5 10 15 20 25
row = 5
for i in range(1,row + 1):
c = 0
for j in range(1, i + 1):
print(i+(5*c), end=’ ‘)
c += 1
print()
Please write code to print this pattern:-
1
2 7
3 8 13
4 9 14 19
5 10 15 20 25
row =5
for i in range(1,row+1):
for j in range(i):
print(format(i+(j*row),”2d”),end=” “)
print()
1
2 3
4 5 6
7 8 9 1
2 3 4 5 6
7 8 9 1 2 3
4 5 6 7 8 9 1
n=7
counter=1
for i in range(n):
for j in range(i+1):
print(counter,end=” “)
counter=counter % 9 + 1
print()
n=int(input())
for i in range(n):
var=i+1
for j in range(i+1):
print(var,end=” “)
var+=n
print()
please teach me how to display a pattern by entering a number first, like number 4…use
pattern = int(input)
– – – – – 4
– – – -3 4 5
— -2 3 4 5 6
-1 2 3 4 5 6 7
please teach me how to display a pattern by entering a number first, like number 4…use pattern = int(input)
4
3 4 5
2 3 4 5 6
1 2 3 4 5 6 7
Thank you more
input=7
output
1 1
2 2
3 3
4
3 3
2 2
1 1
n=int(input("enter the number"))k=int(input("enter the number"))
a=n+k
b=a
for i in range(1,n+1):
if i<k:
print(a)
a=a+b
elif i==k:
print(k)
else:
a=a-b
print(a)
x=int(input("input= "))mid=x//2+1
for i in range(1,mid):
print(i,i)
print(mid)
for i in range(mid-1,0,-1):
print(i,i)
n=3
for loop in range(1,8):
if loop<4:
for i in range(1,3):
print(loop,end=" ")
print("\n")
elif loop==4:
print("4",end=" ")
print("\n")
else:
for i in range(1,3):
print(n,end=" ")
n-=1
print("\n")
*
*1*
*121*
*12321*
*121*
*1*
*
pls answer this one
n=int(input())
for i in range(n):
for j in range(i+1):
if j==0:print(‘*’,end=””)
else:print(j,end=””)
for j in range(i):
if j==i-1:
print(“*”,end=””)
else:
print(i-j-1,end=””)
print()
x=n-1
for i in range(x):
for j in range(x-i):
if j==0:
print(“*”,end=””)
else:
print(j,end=””)
for j in range(x-i-1):
if j==x-i-2:
print(“*”,end=””)
else:
print(x-i-2-j,end=””)
print()
can anyone solve this pattern
24
23 22
21 20 19
18 17 16 15
14 13 12 11 10
x=24for i in range(5):
for j in range(i+1):
print(x,end=" ")
x-=1
print()
great job sir
hats of to you..
an alternative solution to the random number pattern.
for i in range(1,9):k = 2
for j in range(i*2-1):
if 2**j=2**i:
print(2**(i-k),'',end='')
k = k + 1
print()
an alternative solution to: “Print reverse number from 10 to 1”
k = 0for i in range(5):
for j in range(i):
print(k+i-j,'',end='')
k = k+i
print()
How can you get this output:
enter a number: 50
a=50c=1
for i in range(1,a+1):
b=""
for j in range(i):
if c<=50:
b=b + str(c)
c=c+1
print(b)
x=1brk=False
n=int(input("Enter the number: "))
for i in range(n):
for j in range(i):
if x<=n:
print(x,end='')
x+=1
else:
brk=True
break
if brk==True:
break
print()
Can anyone help me make a pyramid where the length of the left side scales based on a entered integer using loops? ex
Enter an integer between 1 and 5: 5
1 2 3 3 4 5 4 5 6 7 5 6 7 8 9please solve this
can you please elaborate the question
n=int(input("Enter Number: "))for i in range(1,n+1):
for j in range(i,0,-1):
print(n+1-j,end=" ")
for j in range(n-i):
print(n-1-j,end=" ")
print()
x=1n=int(input("Enter the number: "))
for i in range(1,n):
print(" "*(3*(n-i)),end="")
for j in range(i):
print(x,end=" ")
x+=1
x=(x-i)+1
print()
n=int(input())for i in range(1, n+1):
print(" "*(3*(n-i)),end="")
for j in range(i):
print(i+j, end=" ")
print()
for loop in range(1,6):
for i in range(5,loop,-1):
print(” “,end=” “)
n=loop
for i in range(1,loop+1):
print(n,end=” “)
n+=1
print(“\n”)
* *** ***** ******* &&&&&&&&& ******* ***** *** *9 9 9 9 9 9 9 9 9 7 7 7 7 7 7 7 5 5 5 5 5 3 3 3 1x=int(input("Enter Number of rows: "))for i in range(x):
print(" "*(2*i),end="")
for j in range(2*(x-i)-1):
print(2*(x-i)-1,end=" ")
print()
n=int(input("Enter Number of rows(odd): "))x=n//2
for i in range(x):
print(" "*(x-i),end="")
print("*"*(2*i+1))
print("&"*(2*x+1))
for i in range(x-1,-1,-1):
print(" "*(x-i),end="")
print("*"*(2*i+1))
Or this:
if wrong, please mention
a=int(input())for i in range(2,a+1):
b="1 "+" "*(2*i-4)+str(i)
print(b)
for loop in range(6):
print(“1″,end=” “)
for gap in range(0,loop):
print(” “,end=” “)
print(loop+1,end=” “)
print(“\n”)
Someone, please print this:
can you please elaborate the question
a=int(input())for i in range(1,a+1):
b=""
for j in range(1,a-i+2):
b=str(j)+" "+b
print(b)
Wap to print all the pattern
a="#@"c=""
for i in range(int(input())):
if i%2==0:
b=a[0]
else:
b=a[1]
c=c+b
print(c)
#in place of the index, you can directly assign them separately
How to wap this pattern
b=int(input())n=""
m=1
a=0
for i in range(1,b+1):
n=n+ str(i)
m=m*i
a=a+ i
print(n+" "*(b)+str(m)+" "*(b)+str(a))
I cannot maintain the spaces, if any one knows, please mention it.
How to print this pattern
Complete the code to find if a given number is a prime number? The program will take a positive integer greater than 1 as input and indicate if it is a prime number by saying “prime”, and if it is not a prime number saying “not a prime”. Note there are 3 places in the given code that you need to fix for this code to work properly and give the expected output.
Complete the code to find if a given number is a prime number? The program will take a positive integer greater than 1 as input and indicate if it is a prime number by saying “prime”, and if it is not a prime number saying “not a prime”. Note there are 3 places in the given code that you need to fix for this code to work properly and give the expected output.
how to print this
input result
please help to fill this code
Write a program to print the below number pattern
for n=6
Use a variable ‘n’ in the program to control the number of output rows
As here for n=6, the number of rows is 6
Can someone pls help me with this?
It’s so hard in Python
s1="APPLE"for i in range(1,len(s1)+1):
print(s1[:i])
a=”APPLE”
for loop in range(6):
for i in range(loop):
print(a[i],end=” “)
print(“\n”)
How to print
I want a program of this pattern please help,
num=5for i in range(5):
for j in range(0,i+1):
if j%2==0: print(0, end='')
else:
print(1,end='')
print()
n=10x=1
for i in range(n):
for j in range(i+1):
print(x%2,end="")
x+=1
print()
*************** ******* ****** ***** ***** *** *** * *Pls solve this
please i need answer:
Write a program to display a shape using star (*) based on the user selection. The program
will repeatedly ask the user to determine the shape number (any number from 1-6, see
below) and its parameters (i.e. width, height). The program will stop asking the user for
more inputs only when the user inputs 7 (which means exit).
The user will see the following menu:
1: Square
2: Rectangle
3: Left Lower Triangle
4: Right Lower Triangle
5: Left Upper Triangle
6: Right Upper Triangle
7: Exit
Enter the number of the shape you want to be drawn on the screen:
– In case the user selected 1, you will ask the user to enter the length of the square,
and your program will then call a function that will draw the square based on the
given length.
– In case the user selected 2, you will ask the user to enter the width and the height of
the rectangle and your program will then call a function that will draw the rectangle
based on the given width and height
– In case the user selected 3 or 4 or 5 or 6, you will ask the user to enter the length of
the triangle. In your code, you will write 4 functions to draw the corresponding 4
triangle types based on the given length.
For example, given a length=5
o Left Lower Triangle function will draw:
o Right Lower Triangle will draw:
o Left Upper Triangle will draw:
o Right Upper Triangle will draw:
– In case the user selected 7, your program should stop running
– In case the user selected a number, not in the range (1-7), your program will print a
message “invalid selection, try again”, and the menu should be displayed again.
– After a user select any of the number 1-6, and after drawing the required shape, the
the menu should be displayed again asking the user for a new selection.
I’m looking to solve the following:
Write a program that accepts a positive integer, N, that represents the number of rows of a right triangle. Each row of the triangle consists of one or more ‘*’ characters. Use a while loop or a for loop, to print the right triangle of the character ‘*’ where the triangle is one character wide at its narrowest point and N characters wide at its widest point. Then, display a blank line followed by the number of times the ‘*’ character is shown in the triangle.
Sample Input – 9
Sample output:
45
____________________________________
What I have so far:
_________________________________
>>>
__________________________________
Not sure how to calculate or display the total number of (*’s) listed.
Also, not sure if needed, but it would be cool to have a message printed stating that “only positive integers are accepted in this code”, if a negative integer is input as a value for ‘N’. Or something like this. Just trying to add some flair to the program.
n=9count=0
for i in range(n+1):
for j in range(1,i+1):
print("*", end='')
count+=1
print()
print("Total stars =",count)
Just increase the count by 1 each time you print a star
A static program to print 1
3 2
6 5 4…..
I need help with this code
Need Help
Print Pattern
n=5for i in range(1,n+1):
for j in range(2*i):
print(i,end="")
print()
print("*"*(2*i+1))
can anyone tell code for this pattern
n=int(input())for i in range(n,0,-1):
for j in range(1,i+1):
print(n-i+j,end="")
print()
for i in range(1,n):
for j in range(i+1):
print(n-i+j,end="")
print()
Can anyone help me out with this
n=int(input())vfor i in range(1,n+1):
for j in range(1,n+1):
if i==1 or j==1 or i==n or j==n:
print("*",end='')
else:
print(' ',end='')
print()
Please help to solve the pattern
Thank you
Hi Vishal, can u please help in solving the following patterns of rows “n”
* * * * * * * * * * * *and
n=10print("_"*(n+1))
for i in range(n):
print("|",end="")
print(" "*(n-i-1),end="")
print("/")
Pattern double number on each column using while loop
there is some problem with this website sir
mine (
j<=1) and if the statement is not printingPlease check asap
Practise Problem
Pattern using while loop
the first solution is kind of wrong
this is the right solution
I nee code for the following out put in python
1
4 9
16 25 36
49 64 81 100
Even number pattern using while loop
Double the number pattern using while loop
Pattern with a combination of numbers and stars
want this output
Here is the solution to this question
Given an integer N, write a program to print a right angle triangle pattern similar to the pattern shown below
/| / | / | / | /____|Input
The input will be a single line containing a positive integer (N).
Output
The output should be N lines containing the triangle pattern.
Please help me with this pattern
who can draw it for Me !!
Here is the solution for your question
Plz anyone tell me how this pattern form
***** **** *** ** * ** *** **** *****Output:
Can you please help me with this kind of pattern, thank you.
Enter the number of line: 10
#Here is the solution for your question
kindly solve this
Can you please help me with this pattern
Hey Vishal,
My self Snehal. I have been following your pynative work for almost a year now.
I am a beginner at Python. I sometimes get stuck. I need questions to practice as well.
You are helping me with this. Especially with patterns. I wanted to try nested for but I didn’t know how to practice. I got it now.
Thank you so much.
I am glad it helped you Snehal.
can you draw this in python with for loops
Please, can you help me to print this pattern :
* ####*#### ########*######## ####*#### *I tested different methods but I can’t have exactly the same pattern
if possible, I need a code with for and while loop
I’m a beginner in Python, so I need more methods for learning
thank you very much
1 2 3 2 3 4 5 4 3 4 5 6 7 6 5 4 5 6 7 8 9 8 7 6 5How to print this pattern?
Reverse triangle to get a result like
2 loops were never really needed.
Kindly help with the below pattern
Sample Input 1:
5
Sample Output 1:
How to write this pattern in python?
Enter the number of Rows:6
Somebody please help me to print this shape. Thanks
Write a program that prompts the user for an integer n, and then prints the drawing as shown in the run examples. The drawing is made up of n bars, where the length of the first bar is 1, the second 2, …., n. The maximum possible value of n will be 9.
Wonderful supportive programs to understand the fundamentals of Python coding!
| | + | | | + + | + + + + + + + + + |+ + +| | |+ +| | | | |+| | | | | ||| | | |Any Idea How to Do this?
HELP, Please print the following pattern as it is in python
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *PLEASE HELP FOR THIS CODE.Uegent please, Write a program in PYTHON to calculate the parking charges of a vehicle. Enter the type of vehicle as a character (like c for car, b for bus, etc.) and read the hours and minutes when the vehicle enters the parking lot. When the vehicle is leaving, enters its leaving time. Calculate the difference between the two timings to calculate the number of hours and minutes for which the vehicle was parked. Calculate the charges based on the following information:
Vehicle Name Rate till 3 hours Rate after 3 hours
Truck / bus Rs 20 30
Car Rs 10 20
Scooter /cycle/ Motor cycle Rs 5 10
Can anyone help me to print below pattern
Will print the same cane the values
1 4
2 3
2 3
1 4
Hello can you help me with this code please??
hi!
your site is really very helpful!
i have a question,
can you please tell me that why in 17th question did you use a in
range of (i)and then you printed a space?? see because i have value from 0 to 6 and if we use this later after printing “j”, what happens to 4 and 5th value of i? like where does this space will be includedCan you write this program ?
how to print this pattern in python that accepts no of rows to be printed as input
1 2 3 4 5 2 3 4 5 3 4 5 4 5 5can anyone help me to print this pattern for 1st 2nd and nth input terms?
please tell me how to print this pattern
st=’CSK’
provide the codes for printing as above (input will be no. of row)
The output for the first solution is not correct.
the output from the code:
the desired output:
Can I get a solution to print this pattern?
1 232 34543 4567654 567898765please notice that if we write range(1,6) that means it will include 1,2,3,4,5 but not 6.so if you want loop to be executed 5 times you have 2 options
range(0,5)or
range(1,6)How to print.
1
23
456
78910
Hey, Please find below the solution
Generating Binomial Distribution
Description
Generate a binomial distribution, tested 10 times, given the number of trials(n) and probability(p) of each trial.
The input will contain seed, n, and p in the same order.
The output should contain a numpy array with 10 numbers representing the required binomial distribution.
Hint: You can use numpy’s random number generator here too. Remember to set the seed before generating numbers to ensure the correct output.
Sample Input:
0
10
0.5
Sample Output:
[5 6 5 5 5 6 5 7 8 5]
Hello Vishal. I loved your article. I have been struggling with pattern printing questions since some time. Your simple coding steps and explanation in the begining of article has helped me alot. Thanx a lot for the compilation of the pattern printing questions. Great job!!
You are welcome, Saily.
How can I print the below pattern with loops?
rows = int(input("Enter the number of rows: ")) for i in range(1,rows+1): for j in range(i,0,-1): print(j,end=" ") print()Above code is for the question asked by phudki
i need output for the following pattern:
* * # * * # # *please do this needful..
Please print code for this
rows=4 for i in range(1,rows+1): for j in range(i+1): if j==0: print(i,end=' ') else: print('*',end=' ') print('\r')Print this?
1 2 2 3 3 3 4 4 4 4 5 5 5 5 5code for this?
rows = int(input("Enter number of rows: ")) for i in range(0,rows): for j in range(0,rows): if(j<rows-i-1): print(" ",end=" ") else: print(i+1,end=" ") print()#This code is for the question asked by uuu
How to print this using a while loop?
print the following number triangle using while loop
Could you please try a diamond pattern in which the stars(‘*’) will have 2 pyramids mounted on each other’s base
Yes. I will add
Hii
Please help me with this pattern
def pattern(n): k = n - 1 for i in range(0, n): for j in range(0, k): print(end=" ") k = k - 1 for j in range(0, i + 1): print('* ', end="") print('\r') pattern(5)How to print below pattern:-
How can I print this
write a program that inputs the number of rows and print this
don’t know
I am not asking you..Please don’t waste your word unnecessary.
a=int(input()) for i in range(0,a): c=1 print(c,end=' ') for j in range(a-i-1,0,-1): print('*',end=' ') c=c+1 print(c,end=' ') print('\n')use
end="*"in printCode for this, please??
for N=3
How to build an N height pyramid (N=3) with 2 stars at the top and 2 stars for feet for the second and penultimate columns.
or for N=4
for N=3
How to build an N height pyramid (N=3) with 2 stars at the top and 2 stars for feet for the second and penultimate columns.
** **** ****** * *Code for this Pattern
Coding for this one
a=input("enter the word") b="" for i in a: b=b+i print(b)?
How to build an N height pyramid (N=3) with 2 stars at the top and 2 stars for feet for the second and penultimate columns.
how do I print
11111
2222
333
44
5
Code for this?
How to print this?
n=int(input("enter no of rows:")) for i in range(1,n+1): for j in range(1,i-1): print(j,end="") for j in range(i-1,0,-1): print(j,end="") print()make sure to use the identation
How to print this pattern
.
Output below is
a=int(input("enter your no")) b=0 for i in range(a,0,-1): b=b+1 for j in range(1,i+1): print(b,end='') print('\n')How to write a program that prints out the triangle of star(s) depending on the input,
n, by follow the pattern in the following samples using while-loop
Sample Run#2
n=int(input()) for i in range(1,n+n): for j in range(1,i+1): i=i%2!=0 print('*'*i,end=' ') print()?
How do I print out
as well as
Thank you
a=20 # or a=int(input()) if it is a user input question print("#"*a,end="\n") #its the first line of pattern i=(a//2)-1 j=2 while(i!=0): while(j<=(a-2)): print("#"*i,end="") print("_"*j,end="") print("#"*i,end="\n") i=i-1 j=j+2hope this helps 🙂
How we can create continue pattern of rainfall effect using a diamond pattern
Print must be like as
1 2 3 1 2 1 1 2 3 1 2… continue
Here 1 2 3 represent diamond has to print this type of manner
how will we print
how to print
n = 5 k = 5 for i in range(0,n+1): for j in range(k-i,0,-1): print(j,end=' ') print()Someone solves this…
a=int(input()) l1=[*range(1,a+1)] for i in range(1,a+1): for j in range(a,i-1,-1): if(i==1): print(l1[a-j],end=' ') elif(j==a): l1[a-j]=i print(l1[a-j],end=' ') else: l1[a-j]=l1[a-j]*l1[a-j-1] print(l1[a-j],end=' ') print()we cant understand this reply… please write program in simple pl.
How to print this?
a=int(input()) for i in range(0,a): for j in range(0,i+1): print(i*j,end=' ') print()Code for this?
1 2 3 4
2 3 4
3 4
4
n = int(input()) i = i + 1 for i in range(0,n+1,1): for j in range(i+1,n+1,1): print(j,end='') print()1
3*2 4 *5 *6 10 *9 *8 *7please give an answer for this output
* * * *
* * *
* *
*
* * * *
* * *
* *
*
for i in range(0,4): for j in range(4-i): print("*", end="") print("\n")it gives an invalid syntax error to the equals to sign in every such code for printing patterns…
* * * *
* * *
* *
*
How to do this
how to print this like
*
**
***
****
for i in range(1, 5) : for j in range(i) : print "*", printfor i in range (0,4): for j in range (0,I+1): Print ("*" , end="") print()how to print
receives an integer n as a parameter and displays a pattern of stars on the screen
a=int(input()) for j in reversed(range(1,a+1)): print('*'*(a*j))if I give input like 5,2,3
output like
/ / \ / / \ / / / / /Please help me to solve this
for i in range(0,6): for j in range(5,i,-1): print(j,'',end='') for l in range(i): print(' ',end='') for k in range(i+1,6): print(k,'',end='') print('\n')Please tell me the program of these outputs:
1, 1, 2, 4, 4, 8, 8, 16, 16, upto n numbers,
how to print this?
for j in range(0, i + 1):
how code actually works
in pyramid
1
33
555
7777
99999
print the above pattern !
print("Enter Limit: ") n = int(input()) i = 1 while(i<=n): j = 1 while(j<=i): print((i*2-1), end="") j = j + 1 i = i + 1 print()I have a better code with O(n) complexity to print the pattern given below-
* * * * * * * * * * * * * * * code- n = 5 for j in range(1,n+1): print("* " * j)how do i print this one?
print("Enter limit: ") n = int(input()) i = 1 while(i <= n): j = 1 while (j = j): print(format(i, "2d"), end=' ') else: print(format(j, "2d"), end=' ') j = j + 1 print() i = i + 112345
22345
33345
44445
55555
how do i print this one?
a=int(input()) for i in range(1,a+1): for j in range(1,a+1): if(j<=i): print(i,end=' ') else: print(j,end=' ') print()how to print this?
its pretty simple….
take your code editor and ask someone to do this for you and take the credit.
after writing the code press run or f5 then itll be printed.
1 1 2 1 1 2 3 2 1 1 2 1 1please help me to write “”bottom part of this diamond of numbers””
1 1 2 1 2 3 1 2 3 4 1 2 3 4 5Please Solve this number pattern 9in Python
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * *I need program for your pattern please
* * * * *
* * * *
* * *
* *
*
pls help some bady
*
* *
* * *
* * * *
* * * * *
i also need it….plz if anyone can help.
num = 5 for row in range(num) print("* " *(row+1)) for row in range(num): print("* " *(num-row))num = 5 for row in range(num): print("* "*(row+1)) for row in range(num): print("* "*(num-row))program for this ?
for i in range(1,6): for j in range (1,6): if j<=i: print(i,end='') print()n=int(input("enter a number:")) for i in range (1,n+1): for j in range(1,i+1): print(i,end=" ") print( )row = 5 for i in range(row): for j in range(0, i): print(i, end="") print("\n")how do I print this
*****
*
*
*
*
*****
Program for this output Write a program to print the following pattern:
1 2 2 3 3 3 4 4 4 4How do make this 5 * 10 grid by using random function and each row have only one ‘O’ and the position are random?
what is the code for this pattern in python
1 2 3 4 5 6 7 8 9 2 3 4 5 6 7 8 3 4 5 6 7 4 5 6 5what is the code for this pattern in python
a=int(input()) for i in range(1,a+1): for j in range(1,(a*2)-i+1): if(j<i): print('*',end='*') else: print(j,end=' ') print()How to get this?
Input number : 3
Expected Output :
* * * * *for i in range(1,n+1): for j in range(1): if i==1: print(i*"*",end="") else: print(2*"*",end="") print()create the following pattern
n=5 for i in range(n): for j in range(n): if j==i: print("1",end="") else: print("0",end="") print()Plz print this pattern its. Urjent
n=5 for i in range(n): for j in range(i+1): print("*",end="") print()n=5 for i in range(1,n+1): for j in range(1): print((2*i-1)*"*",end="") print()plz kindly tell me how to make this?
i need it urgently..
rows = input("Enter number of rows ") rows = int (rows) for i in range (rows, 0, -1): print((rows-i) * ' ' + i * '*')How can I print this? has to work on Adhesive python
THIRD
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *Here is the basis code to use:
for i in range(3): for j in range(3-i): print("*", end=" ") print("")Write a program that uses nested loops to draw this pattern:
Write a program that uses nested loops to draw this pattern:
Enter your age, then print that many stars (*) in one line
* ** *** **** ***** **** *** ** ** ** *** **** ***** **** *** ** *1 232 34543 4567654 567898765 67890109876 7890123210987 890123454321098 90123456765432109 0123456789876543210this is supposed to look like a tree. not like this. idk why this wasn’t spaced out
def pypart(n): for i in range(0, n): for j in range(0, i+1): if j % 2 == 1 : print("0 ",end="") else : print("1 ",end="") # ending line after each row print("\r") # Driver Code n = 5 pypart(n)Pattern for this!!!
x=1
for y in range(0,5):
for z in range(y+1):
print(x%2,”,end=””)
x+=1
print()
I have some question
1. why we are using end = ‘ ‘? wht is the purpose of it.
2. need explanation for 3rd argument in range() ex- rage(1, 11, -1)
Hi Sohair,
end = ‘ ‘used to have space between numbers or stars.For example, if we executing loop 5 times and in each iteration we are printing
print("*", end=', ')this statemment. this will print*,*,*,*,*For second question
range(11, 1, -1)this will print range in reverse order. i.e.11, 10, 9....0For better understanding on range function please refer to Python range() functionn=3
n=5
the print above pattern in python
https://paste.pound-python.org/show/ABB0xOHlvRVauIaa6lpV/
Need help with this.
sir, I want this program
# * # * # * # * # * # * # * # * # # * # * # * * # * # * # * # * # #ais tarha ka patteren inverted pyramid form ma
Please print below pattern
1 2 1 2 3 1 2 3 4 1 2 3 4 5Help its urgent
Hi Shashank its already there in examples please check
Sir I want full triangle pattern not right triangle pattern
* * * * * * * * * *how will we do this??
n=4
for i in range(n,0,-1):
for j in range(n,0,-1):
if i>=j:
print(‘*’, end=’ ‘)
else:
print(‘ ‘, end=’ ‘)
print(”)
Hello,
How do you write this function using recursion?
print("Program to print start pattern: \n"); rows = input("Enter max star to be display on single line") rows = int (rows) for i in range (0, rows): for j in range(0, i + 1): print("*", end=' ') print("\r") for i in range (rows, 0, -1): for j in range(0, i -1): print("*", end=' ') print("\r")Thank you,
Mary
how to make this one!
How can i do an input string to *
You can refer our article https://pynative.com/python-input-function-get-user-input/
Just like this but if we have any words like input
hello everyone ,do you know how to display
print("1 2 3") print("4 5 6") print("7 8 9")1 2 2 2 3 3 3 3 3 4 4 4 4 4 4 4how do we make this one?
n=int(input("enter a number of row")) count=1 for row in range(1,n+1): for col in range(1,row+count): print(row,end="") count=count+1 print()I NEED A PROGRAMME FOR THE FOLLOWING PATTERN
* * * * * *I need to program for the following pattern
for i in range(4): current=4 increment=0 for j in range(4): print(current-increment,end="") if(increment<i): increment=increment+1 print()n = int(input()) for i in range(1, n): num = n for j in range(1, n): print(num, end='') if i > j: num-=1 for j in range(n,n+1): print(n+1-i,end='') num=n for j in range(1,n): print(num+1-i,end='') if n-ij: num-=1 for j in range(n,n+1): print(i+1,end='') num=i+1 for j in range(1,n): print(num,end='') if j>=i: num+=1 print()counter = 1 while counter < 4: print(counter * "*") counter +=1hey, can anyone help me with this code? It must be done using for and if only.
0 1 0 1 2 1 0 1 2 3 2 1 0 1 2 3 4 3 2 1 0 1 2 3 4I tired and think every stuff but I don’t understand what I am missing. I am having an issue with generating 101, 21012, 3210123, 43211234
here is my code(which is wrong)
for i in range (1,6): for t in range (i,5): print('\t', end="") for j in range (0,(2*i-1)): print(2*i-1-j, "\t", end="") print("")Can you please provide the exact output you need
How to get this pattern?
some help on this?
Hey Axile28. Please check Example 4: print Asterisk (Start) pattern
n = int(input("enter a num")) i=1 while i<=n : print("*"*i) i+=1 j=1 while j<=n : print("*"*(n-j)) j+=1for i in range(1,6): print("####")The code is wrong. A j loop is required for initial spaces.
* *2* *232* *2* *How Can I Make This Patteran In Singal loop?
0 101 21012 3210123 432101234 54321012345n=int(input("enter no.")) for i in range(0,n+1): for j in range(i,0,-1): print(j,end="") print(0,end="") for k in range(1,i+1): print(k,end="") print()Guys help in printing this pattern.
how can I print this?
1 2 3 4 5 6 2 3 4 5 6 3 4 5 6 4 5 6 5 6 6end =” ”
Sorry for wrong typing
slove this
n=int(input("enter no.")) for i in range(1,n+1,2): for j in range(i,n+1,2): print(j,end=" ") print()How can i get this pattern:
123456
78912
3456
789
12
3
For this pattern:
Hey Rick. The solution is added. Please check example 7
I want python program for this pattern, please
1 2 3 4 5 6 7 8 9Thank you for your question. I have updated the article. Please check number pattern example 6
x = int(input("enter no. of rows")) n=1 for i in range(1,x*2,2): for j in range(0,i): print(n,"",end="") n=n+1 print()How do I make an hourglass shape with stars
******* ***** *** * *** ***** ******* *********s1 = 0 e1 = 7 s2 = 0 e2 = 0 for x in range(4): for y in range(s2,e2): print(" ",end="") for z in range(s1,e1): print("*",end="") print() s1 += 1 e1 -= 1 e2 += 1 s1 -= 1 e1 += 1 e2 -= 1 for x in range(3): s1 -= 1 e1 += 1 e2 -= 1 for y in range(s2,e2): print(" ",end="") for z in range(s1,e1): print("*",end="") print()# star Program def first(n): for i in range(0, n): for j in range(i,n ): print('* ',end='') print("\r") for i in range(0, n): for j in range(0, i+1): print('* ',end='') print("\r") inp = input('Enter The Numbers Of Rows ') inp = int(inp) first(inp)n=int(input("enter a number : ")) for i in range(n,0,-1): print("*"*i) for j in range(1,n+1): print("*"*j)n=int(input("enter number : ")) for i in range(n,0,-1): print("*"*i) for j in range(1,n+1): print("*"*j)previews commented wrong code by mistake
n=int(input("enter a number : ")) for i in range(n,0,-2): print("*"*i) for j in range(2,n+1,2): print("*"*j)How do you make this with a with a while loop?
num=int(input('Enter a number: ')) while num<=0: print('Error! Enter a positive number: ') num=int(input('Enter a number: ')) for row in range (num): for col in range (row): print('*', end='') print() for i in range (num,0,-1): for j in range (i): print('*', end='') print()How can we do this
n = int(input("enter a num")) for i in range(1,n): for j in range(1,i+1): print(j,end="") print() for i in range(n,0,-1): for j in range(1,i+1): print(j,end="") print()n = int(input("enter a num")) i=1 while i<=n : print("* "*i) i+=1 j=1 while j<=n : print("* "*(n-j)) j+=1n = int(input()) k = 0 for i in range(n,0,-1): k += 1 for j in range(i,0,-1): if j <= k: print('#',end = '') print(' ')for i in range(1,6): for j in range(1,i+1): print("*",end=" ") print("")for x in range(5,1,-1): for y in range(1,x): print("*", end =" ") print("")How do we make this one?
Is it possible for you to create a Python program for this pattern, please?
for i in range(4): for j in range(4-i): print(chr(65+i),end='') for j in range(4-i): print("*",end='') for j in range(4-i): print(chr(65+i),end='') print('\n',end='')n=5 for i in range(0,n): print(chr(65+i)*(n-i), end="") print("*"*(n-i), end="") print(chr(65+i)*(n-i), end="") print()star = '*' counter = 1 out = 0 print("Pattern1") while counter < 6: out = counter * star print(out) counter +=1 counter = 5 while counter !=0: out = counter * star print(out) counter -=1write counter = 4 insted of counter=5
n=int(input("enter the number")) for i in range(1,n+1): s= '*'*i print(s) for j in range(n+1,1,-1): y = '*' * j print(y)n = int(input("enter a num")) i=1 while i<=n : print("*"*i) i+=1 j=1 while j<=n : print("*"*(n-j)) j+=1First by the simple code i in0,6 and j in 0,i and then reverse i in 6,0,-1 and again j in 0,i
how do we make this one?
n=int(input("Enter the number:")) z=0 for x in range(0,n): for y in range(0,x+1): print(z,end='') z=2**(x+1) print()https://paste.pound-python.org/show/ABB0xOHlvRVauIaa6lpV/
Please help me with this.
e=int(input("Enter the number:")) n=0 for i in range(1,e+1): for j in range(0,i): print(n,end=" ") n=2**i print()I want this pattern in python
num=int(input("enter no. of rows : ")) for i in range(num): val=i+1 for j in range(i+1): print(format(val, "<4"), end="") val=val+((num-1)-j) print()print("1 2 6 3 7 10 4 8 11 13 5 9 12 14 15");d=4f=0
for i in range(1,n+1):
print(i,end=" ")
f=i+d
for j in range(1,i):
print(f,end=" ")
d-=1
f += d
print()
d=4
d=4f=0
for i in range(1,n+1):
print(i,end=" ")
f=i+d
for j in range(1,i):
print(f,end=" ")
d-=1
f += d
print()
d=4
1 1 2 1 2 3 1 2 3 4 1 2 3 4 5Print the above pattern in python.
for i in range(1,6): for j in range(1,i+1): print(j,end=' ') print( )Right
Hey Blaize.
I have updated the post with your question. Please check
How to print this pattern in python?
---------.|.--------- ------.|..|..|.------ ---.|..|..|..|..|.--- -------WELCOME------- ---.|..|..|..|..|.--- ------.|..|..|.------ ---------.|.---------Will check and let you know
N, M = map(int,input("Enter input: ").split()) for i in range(1,N,2): print((i * ".|.").center(M, "-")) print("WELCOME".center(M,"-")) for i in range(N-2,-1,-2): print((i * ".|.").center(M, "-"))How to print “M” in star(*)
Hey Mahesh
print("m ", end=' ')instead of
print("* ", end=' ')N=5 for I in range(1,n+1): K=1 for j in range(1,n+1): If i>=j: Print(k,end=' ') Else: Print(' ',end=' ' ) Print()num=6 for row in range(1, num): for column in range(1, row + 1): print(column, end=' ') print("")# star Program def first(n): for i in range(0, n): for j in range(0, i+1): print(j+1,end='') print("\r") inp = input('Enter The Numbers Of Rows ') inp = int(inp) first(inp)lastNumber = 6 for i in range(1 , lastNumber): for j in range(1 , i+1): print(j , end="") print(" ")print("Second Number Pattern ") lastNumber = 6 for row in range(1, lastNumber): for column in range(1, row + 1): print(column, end=' ') print("")for i in range(1,n+1): for j in range(1,i+1): print(j,end="") print()def pattern(n): for i in range(1,n+1): for j in range(1,i+1): print(j ,end=' ') print() n=int(input("How many row you want to enter?")) pattern(n)print("Second Number Pattern ") lastNumber = 6 for row in range(1, lastNumber): for column in range(1, row + 1): print(column, end=' ') print("")row = int(input("Enter size")) for row in range(1, row): for column in range(1, row + 1): print(column, end=' ') print("")How to print prime numbers in pyramid pattern?
2 3 5 7 11 13 17 19 23 29 31 37 41 43 47for i in range(1,6): for j in range(5,i,-1): print(" ",end=" ") for k in range(1,i+1): print(k,end=" ") print("")rows = int(input (“enter the number of rows : “))
for i in range(1, rows + 1):
for j in range(1, i + 1):
print(i * j, end=’ ‘)
print()