File tree Expand file tree Collapse file tree 4 files changed +98
-0
lines changed Expand file tree Collapse file tree 4 files changed +98
-0
lines changed Original file line number Diff line number Diff line change 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 ("" )
Original file line number Diff line number Diff line change 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+
Original file line number Diff line number Diff line change 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+
Original file line number Diff line number Diff line change 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 )
You can’t perform that action at this time.
0 commit comments