# Write a Python program to: ask the user to enter two integers: int1 and int2. The program uses the exponential operator to calculate and then print the result when int1 is raised to the int2 power. You also want to calculate the result when int1 is raised to the .5 power; however, you realize that it is not possible to take the square root of a negative number. If the value for int1 that is entered is a negative number, print a message to the user to enter a non-negative number (float). If the user does enter a negative number, you will use a while loop to continue prompting the user until you get a valid number.  Once the user enters a valid number, you calculate and print the square root. Finish the program by printing the values of int1 and int2.

Question
67 views

Write a Python program to: ask the user to enter two integers: int1 and int2. The program uses the exponential operator to calculate and then print the result when int1 is raised to the int2 power. You also want to calculate the result when int1 is raised to the .5 power; however, you realize that it is not possible to take the square root of a negative number. If the value for int1 that is entered is a negative number, print a message to the user to enter a non-negative number (float). If the user does enter a negative number, you will use a while loop to continue prompting the user until you get a valid number.  Once the user enters a valid number, you calculate and print the square root. Finish the program by printing the values of int1 and int2.

check_circle

Step 1

Program Approach-

• Import the essential modules.
• Prompt User to input two numbers.
• Display the result of the expression (first number is raised to the second number power)
• If the number entered by the user for the first input is positive,then program will calculate the square root of that number.
• Use while loop to prompt user to enter the non-negative number,if the user has entered the negative number for the first input.
• Display both the numbers and the square root of the first number.

Variables used -

int1 - to store the first number

int2 - to store the second number

pr - to store the result of expression(first number raised to the second number power)

Step 2

Code -

import math as a # access sqrt() function

#prompt user to enter the two numbers

int1 = float (input ("Please enter the first number : "))

int2 = float (input ("Please enter the second number : "))

#to store the result when first number is raised to the second number power

pr = int1 ** int2

#display the value on the console

print ("First number is raised to the second number power = ", pr)

while(True):

# check whether the first number is negative or not

if (int1 < 0):

print ("Square root of negative number cannot be calculated")

# with the prompt message of type float

int1 = float (input ("Enter the first number (again) : "))...

### Want to see the full answer?

See Solution

#### Want to see this answer and more?

Solutions are written by subject experts who are available 24/7. Questions are typically answered within 1 hour.*

See Solution
*Response times may vary by subject and question.
Tagged in 