Skip to content

Commit 7e14cc3

Browse files
committed
More programs added.
1 parent 54af583 commit 7e14cc3

12 files changed

+320
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
"""
2+
Description:
3+
The prime numbers are basically those numbers which are always divisible by 1 and itself.
4+
divisible means reminder = 0.
5+
like 13, 13 is divisible by 1 and 13 itself so it is prime because it was divisible by exactly two
6+
no's but if we enter a number which was divisible from more than 2 numbers then it was a composite number
7+
like 2,4,6 etc they are composite numbers.
8+
"""
9+
10+
no = int(input('Enter Number to check whether it is prime or not: '))
11+
count = 0
12+
i = 1
13+
while i <= no:
14+
if no % i == 0:
15+
count += 1
16+
i += 1
17+
if count == 2:
18+
print('The Number is prime.')
19+
else:
20+
print('The Number is a composite number.')
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
"""
2+
Description:
3+
factorial is a concept in mathematics it is basically like if we say find factorial of 5 then
4+
5 x 4 x 3 x 2 x 1 = 120, so 120 is the factorial of 5.
5+
"""
6+
7+
no = int(input('Enter Number to find its factorial: '))
8+
originalNo = no
9+
factorial = 1
10+
while no > 0:
11+
factorial = factorial * no
12+
no -= 1
13+
print('Factorial of',originalNo,'is =',factorial)
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
"""
2+
Description:
3+
Fibonacci Series is a concept in mathematics like it is the series in which the elements are like:
4+
0 1 1 2 3 5 8 13 and so on.
5+
In this series it is shown that:
6+
0 + 1 = 1
7+
and 1 + 1(previous number) = 2
8+
2 + 1(previous number) = 3
9+
3 + 2(previous number) = 5
10+
5 + 3(previous number) = 8
11+
8 + 5(previous number) = 13
12+
and the series goes on like this...
13+
"""
14+
15+
no = int(input('Enter Number upto which you want to print fibonacci series: '))
16+
x = 0
17+
y = 1
18+
z = 0
19+
while z <= no:
20+
print(z, end=" ")
21+
x = y
22+
y = z
23+
z = x + y
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
"""
2+
Description:
3+
In this program nested loop concept is used.
4+
"""
5+
6+
i = 1
7+
while i <= 5:
8+
j = 1
9+
while j <= i:
10+
print('*', end=" ")
11+
j += 1
12+
print()
13+
i += 1
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
"""
2+
Description:
3+
Same like program#39
4+
"""
5+
6+
i = 1
7+
while i <= 5:
8+
j = 5
9+
while j >= i:
10+
print('*', end=" ")
11+
j -= 1
12+
print()
13+
i += 1
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
"""
2+
Same like program # 39
3+
"""
4+
5+
i = 1
6+
while i <= 5: # This loop will count the number of row's.
7+
space = 1
8+
while space <= 5 - i: # This loop will print the blank spaces.
9+
print(' ', end=' ')
10+
space = space + 1
11+
j = 1
12+
while j <= i: # This loop will print stars.
13+
print('*', end=' ')
14+
j = j + 1
15+
print()
16+
i = i + 1
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
'''
2+
Description:
3+
Same like program # 42.
4+
'''
5+
6+
i = 1
7+
while i <= 5:
8+
space = 1
9+
while space < i:
10+
print(' ', end=' ')
11+
space += 1
12+
j = 5
13+
while j >= i:
14+
print('*', end=' ')
15+
j -= 1
16+
print()
17+
i += 1
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
'''
2+
Description:
3+
Same like program # 39
4+
'''
5+
6+
k = 1
7+
i = 1
8+
while i <= 5:
9+
space = 1
10+
while space <= 5 - i:
11+
print(' ', end=' ')
12+
space += 1
13+
j = 1
14+
while j <= k:
15+
print('*', end=' ')
16+
j += 1
17+
k += 2
18+
print()
19+
i += 1
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
'''
2+
Description:
3+
Same like program # 39
4+
'''
5+
6+
n = int(input('Enter number of rows: '))
7+
i = 1
8+
while n > 0:
9+
space = 1
10+
while space < i:
11+
print(' ', end=' ')
12+
space += 1
13+
j = 1
14+
while j <= ((n * 2) - 1):
15+
print('*', end=' ')
16+
j += 1
17+
print()
18+
n -= 1
19+
i += 1

Left Angle Triangle Patterns.py

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
"""
2+
First Pattern:
3+
*
4+
* *
5+
* * *
6+
* * * *
7+
* * * * *
8+
9+
i = 1
10+
while i <= 5:
11+
space = 4
12+
while space >= i:
13+
print(' ', end=' ')
14+
space -= 1
15+
j = 1
16+
while j <= i:
17+
print('*', end=' ')
18+
j += 1
19+
print()
20+
i += 1
21+
"""
22+
23+
24+
"""
25+
Second Pattern:
26+
* * * * *
27+
* * * *
28+
* * *
29+
* *
30+
*
31+
32+
i = 1
33+
while i <= 5:
34+
space = 1
35+
while space < i:
36+
print(' ', end=' ')
37+
space += 1
38+
j = 5
39+
while j >= i:
40+
print('*', end=' ')
41+
j = j - 1
42+
print()
43+
i = i + 1
44+
"""
45+
46+
47+
"""
48+
Third Pattern:
49+
1
50+
2 2
51+
3 3 3
52+
4 4 4 4
53+
5 5 5 5 5
54+
55+
i = 1
56+
while i <= 5:
57+
space = 4
58+
while space >= i:
59+
print(' ', end=' ')
60+
space -= 1
61+
j = 1
62+
while j <= i:
63+
print(i, end=' ')
64+
j += 1
65+
print()
66+
i += 1
67+
"""
68+
69+
70+
"""
71+
Fourth Pattern:
72+
1
73+
2 1
74+
3 2 1
75+
4 3 2 1
76+
5 4 3 2 1
77+
78+
i = 1
79+
while i <= 5:
80+
space = 4
81+
while space >= i:
82+
print(' ', end=' ')
83+
space -= 1
84+
j = 1
85+
while j <= i:
86+
print(j, end=' ')
87+
j += 1
88+
print()
89+
i += 1
90+
"""

Pyramid Triangle Patterns.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
'''
2+
To be added...
3+
'''

Right Angle Triangle Patterns.py

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
"""
2+
First Pattern:
3+
*
4+
* *
5+
* * *
6+
* * * *
7+
* * * * *
8+
9+
i = 1
10+
while i <= 5:
11+
j = 1
12+
while j <= i:
13+
print('*', end=" ")
14+
j += 1
15+
print()
16+
i += 1
17+
"""
18+
19+
"""
20+
21+
Second Pattern:
22+
* * * * *
23+
* * * *
24+
* * *
25+
* *
26+
*
27+
28+
i = 1
29+
while i <= 5:
30+
j = 5
31+
while j >= i:
32+
print('*', end=" ")
33+
j -= 1
34+
print()
35+
i += 1
36+
"""
37+
38+
"""
39+
Third Pattern:
40+
1
41+
2 2
42+
3 3 3
43+
4 4 4 4
44+
5 5 5 5 5
45+
46+
i = 1
47+
while i <= 5:
48+
j = 1
49+
while j <= i:
50+
print(i, end=" ")
51+
j += 1
52+
print()
53+
i += 1
54+
"""
55+
56+
"""
57+
58+
Fourth Pattern:
59+
1
60+
1 2
61+
1 2 3
62+
1 2 3 4
63+
1 2 3 4 5
64+
65+
i = 1
66+
while i <= 5:
67+
j = 1
68+
while j <= i:
69+
print(j, end=" ")
70+
j += 1
71+
print()
72+
i += 1
73+
"""
74+

0 commit comments

Comments
 (0)