Python
The function cube should receive a list as a parameter and
return a new list with each
number taken in cubic (raised to three). Write the necessary code
for the function, as well as an example
which uses the function to calculate and print the cubes for the
numbers 5, 8 and 9
Code:
def cube(nums):
ans=[]
for i in nums:
ans.append(i*i*i)
return ans
print(cube([5,8,9]))
Output:
[125, 512, 729]
Get Answers For Free
Most questions answered within 1 hours.