Computer Science, asked by adarshsingh38, 3 months ago

Write a program in Python to enter a integer number, If number is positive
then find out its square root, if number is negative then find out its square,
otherwise if number is zero, print a message "The number is Zero".
with output​

Answers

Answered by anindyaadhikari13
6

Required Answer:-

Question:

  • Write a Python program to enter a integer number. If the number is positive, find out the square root, if the number is negative, find out it's square and if the number is zero, display the message, "It's zero."

Solution:

Here is the code.

import math

n=int(input("Enter any number: "))

if n>0:

print("Square root of the number is: ",math.sqrt(n))

elif n<0:

print("Square of the number is: ",n*n)

else:

print("Number is zero.")

Explanation:

  • At first, we will take a number as input. We will check if the number is greater than zero or not. If it is greater than zero, we will display the square root of the number. If the number is less than zero, we will display it's square and if it's zero, we will display the message that the entered number is zero. This question is solved using if-else-elif conditional construct.

Output is attached.

Attachments:
Similar questions