Skip to content

Commit 05058b9

Browse files
authored
Create swap_elements_in_array.py
1 parent f074120 commit 05058b9

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

swap_elements_in_array.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
list1 = []
2+
i = 0
3+
a = 0
4+
5+
#ask user to create list
6+
print("Input numbers and input @ to stop inputing")
7+
while i < 1:
8+
x = input()
9+
if x == "end":
10+
break
11+
else:
12+
list1.append(x)
13+
14+
#swap elements of list
15+
print(list1)
16+
print("select two positions to be swapped")
17+
n = int(input("first position: "))
18+
m = int(input("Second position: "))
19+
20+
if n <= len(list1) and m <= len(list1):
21+
list1[n-1],list1[m-1] = list1[m-1], list1[n-1]
22+
print(list1)
23+
else:
24+
print("INVALID POSITIONS")

0 commit comments

Comments
 (0)