by CodeChum Admin
You can also make a list of numbers, ey? Let's go and have some fun in tweaking the values of each element, but let's give it some twist to add on some fun to the code.
Let's have a go at it!
Instructions:
Output
The squares and cubes of the elements in the array.
4
1
1
8
27
.
.
.
#Assigning a variable and giving it an array of numbers
nums = [-2, -1, 1, 2, 3, 4, 5 ,6 ,7 ,9, -10, -23, 41]
for num in nums:
if num > 0:
print(num ** 3)
else:
print(num ** 2)
Comments
Leave a comment