Cubes and Squares
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:
- An array containing 40 integer elements is already provided for you in the code editor below.
- Using loops and conditions, print out the cube of the array element if it is a positive number, and print out the square of the number if it is negative. Each result must be printed out separately by each line.
Instructions
- A list containing 5 integer elements is already provided for you in the code editor below.
- nums = [-2, -1, 1, 2, 3]
- Using loops and conditions, print out the cube of the list element if it is a positive number, and print out the square of the number if it is negative. Each result must be printed out separately by each line.
Output
The squares and cubes of the elements in the array.
4
1
1
8
27
.
.
.
Comments
Leave a comment