Question: Given the object oriented programming function as shown below, split the code into ( 1 ) module and ( 2 ) call program ( main

Given the object oriented programming function as shown below,
split the code into (1) module and (2) call program (main program that call on the module). show all the codes
code:
class NumberList:
def __init__(self):
self.numbers =[]
def insert_number(self, number):
self.numbers.append(number)
def search_number(self, x):
if x in self.numbers:
return self.numbers.index(x)+1
else:
return -1
def main():
N = int(input("Enter the number of elements: "))
num_list = NumberList()
print("Enter {} numbers:".format(N))
for _ in range(N):
num = int(input())
num_list.insert_number(num)
X = int(input("Enter the number to search: "))
index = num_list.search_number(X)
if index ==-1:
print("-1")
else:
print("Index of {} is {}".format(X, index))
if __name__=="__main__":
main()

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!