-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoop.py
More file actions
29 lines (21 loc) · 791 Bytes
/
oop.py
File metadata and controls
29 lines (21 loc) · 791 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
"""
Basic concept of Object oriented programming
"""
class InterchangeElements:
"""Class to interchange the first and last element"""
def __init__(self):
self.elements = []
def exchange_elements(self):
print(f"Before exchange: {self.elements}")
temp = self.elements[0]
self.elements[0] = self.elements[-1]
self.elements[-1] = temp
print(f"After exchange: {self.elements}")
def get_input(self):
length = int(input("Enter Length of List: "))
for el in range(length):
self.elements.append(int(input(f"Enter element for {el} index: ")))
if __name__ == '__main__':
interchange_elements = InterchangeElements()
interchange_elements.get_input()
interchange_elements.exchange_elements()