Python Program To Replace The Elements of List With its Cube
In this post, we are going to write a python program to replace the elements of a list with its cube. General Idea : To replace the elements of the list with its cube, we are going to use the list transversing method. We are going to create two empty lists. In first, we are going to input the elements from the user. In second, we are going to fill the elements by the cube of the respective element which is stored in the first list. Pre-Requisites : Python Basics For loop List Manipulation Program : n=int(input("Enter the number of elements :")) l=[] cube=[] for i in range(0,n): x=int(input("Enter the element ")) l.append(x) for i in l: a=i**3 cube.append(a) print(cube) Explanation : 1.In this line, we are inputting the number of elements of the list using the input function and storing that to identifier n. 2.Now we are creating an empty list, for inputting the elements for which we need to replace the cube. 3.Now we are cre...