Intermediate Python

Print the Mutable Lists

The task at hand is to understand Python's way of handling mutable objects like lists when they are passed as arguments to a function. To achieve this, you are required to write a program that should define a function that receives a list as an argument and iterates over the list and multiplies each element by 2, thereby modifying the list.
The program should print out the original list (before modification) and the modified list (after modification). This is to demonstrate that when mutable objects are passed to a function, they are passed by reference, meaning the function can modify the original object.
The first line of the input is an integer n, the number of integers to be entered. The second line contains the n space-separated integers.
The output should print two lines. The first line should contain the original list (before modification) and the second line should contain the modified list (after modification). Both should be displayed in a space-separated format.
5 1 2 3 4 5
1 2 3 4 5 2 4 6 8 10


Time limit: 0.2 seconds

Memory limit: 512 MB

Output limit: 1 MB

To check your solution you need to sign in
Sign in to continue