191k views
4 votes
Two numbers are given (numbers are entered from the keyboard). If both numbers are positive, then output their sum, if both numbers are negative, then output their product, if the numbers are positive and negative, then output the square of a positive number (number ** 2).

Даны два числа (числа вводим с клавиатуры). Если оба числа положительные, то выдать их сумму, если оба числа отрицательные, то выдать их произведение, если числа положительное и отрицательное, то выдать квадрат положительного числа (number**2).

User Chitresh
by
5.6k points

1 Answer

6 votes

Answer:

The program in Python is as follows:

num1 = int(input())

num2 = int(input())

if num1 >=0 and num2 >= 0:

print(num1+num2)

elif num1 <0 and num2 < 0:

print(num1*num2)

else:

if num1>=0:

print(num1**2)

else:

print(num2**2)

Step-by-step explanation:

This gets input for both numbers

num1 = int(input())

num2 = int(input())

If both are positive, the sum is calculated and printed

if num1 >=0 and num2 >= 0:

print(num1+num2)

If both are negative, the products is calculated and printed

elif num1 <0 and num2 < 0:

print(num1*num2)

If only one of them is positive

else:

Calculate and print the square of num1 if positive

if num1>=0:

print(num1**2)

Calculate and print the square of num2 if positive

else:

print(num2**2)

User Ausar
by
5.8k points