File tree 1 file changed +11
-28
lines changed
1 file changed +11
-28
lines changed Original file line number Diff line number Diff line change 4
4
# In[ ]:
5
5
6
6
7
-
8
-
9
7
arr = list ();
10
8
n = input ("Enter the number of elements you want in the array: " )
11
9
12
- print ("Enter the array elements one by one:" )
10
+ # print("Enter the array elements one by one:")
13
11
for i in range (int (n )):
14
- ele = input ( )
15
- arr .append (int (ele ))
16
-
12
+ print ( "Enter the" , i + 1 , "element of the array: " , end = '' )
13
+ arr .append (int (input () ))
14
+
17
15
#Display the original array
18
- print ("Array before rotation is: " )
19
- for i in range (0 , len (arr )):
20
- print (arr [i ])
21
-
22
- #Rotate the given array by 3 times towards left
23
- for i in range (0 , 3 ):
24
- #Stores the first element of the array
25
- first = arr [0 ]
26
-
27
- for j in range (0 , len (arr )- 1 ):
28
- #Shift element of array by one
29
- arr [j ] = arr [j + 1 ]
30
-
31
- #First element of array will be added to the end
32
- arr [len (arr )- 1 ] = first
33
-
34
- print ()
35
-
36
- #Display the array after 3 left rotations
37
- print ("Array after 3 left rotations is: " );
38
- for i in range (0 , len (arr )):
39
- print (arr [i ])
16
+ print ("Array before rotation is:" ,arr )
17
+
18
+ #rotation of the array by 3 elements to left by slicing
19
+ l = arr [0 :3 ]
20
+ del arr [0 :3 ]
21
+ arr = arr + l
22
+ print ('Array after rotation is:' ,arr )
40
23
You can’t perform that action at this time.
0 commit comments