Answer to Question #263963 in Python for Isabel Cortez

Question #263963

2. Cubes and Squares

by CodeChum Admin


Instructions:

  1. An array containing 40 integer elements is already provided for you in the code editor below.
  2. 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.



Output

The squares and cubes of the elements in the array.

4
1
1
8
27
.
.
.
1
Expert's answer
2021-11-11T00:06:51-0500
 #Here you can input integers
input_list = [ 10, -21, 4, -33, 1, 22]


positive_count, negative_count = 0, 0
#creating loop and conditions
for num in l:
    if num >= 0:
        positive_count += 1 and positive_count^3
    else: 
        negative_count += 1 and negative_count^2
#printing our output    
print("Positive numbers in the list: ", positive_count)
print("Negative numbers in the list: ", negative_count)

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS