Skip to content

Commit 75d35e4

Browse files
Merge pull request #747 from yashu762001/master
New Programs On Printing star patterns,rotating a list, selectionSort…
2 parents c7ead71 + 4c18691 commit 75d35e4

File tree

4 files changed

+98
-0
lines changed

4 files changed

+98
-0
lines changed

patterns.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Lets say we want to print a combination of stars as shown below.
2+
3+
# *
4+
# * *
5+
# * * *
6+
# * * * *
7+
# * * * * *
8+
9+
for i in range(1,6):
10+
for j in range(0,i):
11+
print('*',end = " ")
12+
13+
for j in range(1,(2*(5-i))+1):
14+
print(" ",end = "")
15+
16+
print("")
17+
18+
19+
# Let's say we want to print pattern which is opposite of above:
20+
# * * * * *
21+
# * * * *
22+
# * * *
23+
# * *
24+
# *
25+
26+
print(" ")
27+
28+
for i in range(1,6):
29+
30+
for j in range(0,(2*(i-1))+1):
31+
print(" ", end="")
32+
33+
34+
for j in range(0,6-i):
35+
print('*',end = " ")
36+
37+
print("")

rotatelist.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
N = int(input("Enter The Size Of Array"))
2+
list = []
3+
for i in range(0,N):
4+
temp = int(input("Enter The Intger Numbers"))
5+
list.append(temp)
6+
7+
8+
# Rotating Arrays Using Best Way:
9+
# Left Rotation Of The List.
10+
# Let's say we want to print list after its d number of rotations.
11+
12+
finalList = []
13+
d = int(input("Enter The Number Of Times You Want To Rotate The Array"))
14+
15+
for i in range(0, N):
16+
finalList.append(list[(i+d)%N])
17+
18+
print(finalList)
19+
20+
# This Method holds the timeComplexity of O(N) and Space Complexity of O(N)
21+

selectionSort.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
list = []
2+
3+
N = int(input("Enter The Size Of List"))
4+
5+
for i in range(0,N):
6+
a = int(input('Enter The number'))
7+
list.append(a)
8+
9+
10+
# Let's sort list in ascending order using Selection Sort
11+
# Every time The Element Of List is fetched and the smallest element in remaining list is found and if it comes out
12+
# to be smaller than the element fetched then it is swapped with smallest number.
13+
14+
for i in range(0, len(list)-1):
15+
smallest = list[i+1]
16+
k = 0
17+
for j in range(i+1,len(list)):
18+
if(list[j]<=smallest):
19+
smallest = list[j]
20+
k = j
21+
22+
if(smallest<list[i]):
23+
temp = list[i]
24+
list[i] = list[k]
25+
list[k] = temp
26+
27+
print(list)
28+
29+

totaldigits.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# To Find The Total Number Of Digits In A Number
2+
3+
N = int(input("Enter The number"))
4+
count = 0
5+
6+
while(N!=0):
7+
N = (N-N%10)/10
8+
count+=1
9+
10+
11+
print(count)

0 commit comments

Comments
 (0)