0% found this document useful (0 votes)
24 views3 pages

## To Print N No. of Stars in Last Line: Int Input Range Range Range

This Python program contains code to print different patterns like pyramids, diamonds, and stars. It includes functions to print: 1) A pyramid with stars in the last line based on user input n. 2) A pyramid with n lines by decreasing the space and increasing stars in each line. 3) n stars in the nth line of a pyramid by decreasing space between lines of increasing stars. 4) A hollow diamond shape with n*2-1 lines. 5) A full diamond shape with n*2-1 lines by first increasing then decreasing the number of stars per line.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views3 pages

## To Print N No. of Stars in Last Line: Int Input Range Range Range

This Python program contains code to print different patterns like pyramids, diamonds, and stars. It includes functions to print: 1) A pyramid with stars in the last line based on user input n. 2) A pyramid with n lines by decreasing the space and increasing stars in each line. 3) n stars in the nth line of a pyramid by decreasing space between lines of increasing stars. 4) A hollow diamond shape with n*2-1 lines. 5) A full diamond shape with n*2-1 lines by first increasing then decreasing the number of stars per line.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

C:\Users\RuchiBhargava\…nnu\Programs\pyramid.

py
Page 1 of 3 19-09-2019 21:03:27
1 ## to print n no. of stars in last
line
2 n=int(input())
3 x=n//2
4 for i in range(n//2+1):
5 print(" "*x,end="")
6 for j in range(n):
7 for k in range(i+1):
8 if j!=n//2+k and j!=n//2-k:
9 pass
10 else:
11 print("*",end="")
12 print(" ",end=" ")
13 x=x-1
14 print()
15
16 #to print n lines in the pyramid
17 n=int(input())
18 x=n-1
19 y=n+(n-1)
20 for i in range(n):
21 print(" "*x,end="")
22 for j in range(y):
23 for k in range(i+1):
24 if j==(y//2)+k or
j==(y//2)-k:
25 print("*",end="")
- 1 -
C:\Users\RuchiBhargava\…nnu\Programs\pyramid.py
Page 2 of 3 19-09-2019 21:03:27
26 print(" "*x)
27 x=x-1
28
29 ## to print n no of stars in nth line
30 n=int(input())
31 space=n-1
32 for i in range(n):
33 print(" "*space,end="")
34 print("* "*(i+1))
35 space-=1
36
37 ##hollow diamond with n*2-1 lines
38 n=int(input())
39 for i in range(n):
40 for j in range(n+(n-1)):
41 if j==(n-1)-i or j==(n-1)+i:
42 print("*",end="")
43 else:
44 print(" ",end="")
45 print()
46 for i in range(n-2,-1,-1):
47 for j in range(n+(n-1)):
48 if j==(n-1)-i or j==(n-1)+i:
49 print("*",end="")
50 else:
51 print(" ",end="")
52 print()
- 2 -
C:\Users\RuchiBhargava\…nnu\Programs\pyramid.py
Page 3 of 3 19-09-2019 21:03:27
53
54 ##print full diamond of n*2-1 lines
55 n=int(input())
56 space=n-1
57 for i in range(n):
58 print(" "*space,end="")
59 print("* "*(i+1))
60 space-=1
61 space=1
62 for i in range(n-1,-1,-1):
63 print(" "*space,end="")
64 print("* "*i)
65 space+=1
66
67
68
69
70
71
72
73
74
75
76
77
78
79
- 3 -

You might also like