Python
"""Q2: Copy the elements from one list to a new list.
    Your given list:input_ls = [2,1,5,7,3]
    Do the above in for loop as well as in while loop.
    Also implement his inside a method named "copy_elements."""
    
# For loop
input_ls = [2,1,5,7,3]
new_list=[]

for i in input_ls:
    new_list.append(i)
print("Using For loop New_List is:",new_list)



# while loop
input_ls = [2,1,5,7,3]
new_list=[]

i=0
while i < len(input_ls):
    new_list.append (input_ls[i])
    i=i+1
print("Using while loop New_list is:",new_list)

# Using Method call

def copy_elements(input_ls):
    new_list=[]
    for i in input_ls:
        new_list.append(i)
    return new_list

input_ls = [2,1,5,7,3]
copied_list=copy_elements(input_ls)
print("Input list is:",input_ls)
print("Copied list is:",copied_list)
Using For loop New_List is: [2, 1, 5, 7, 3]
Using while loop New_list is: [2, 1, 5, 7, 3]
Input list is: [2, 1, 5, 7, 3]
Copied list is: [2, 1, 5, 7, 3]