In: Computer Science
1. 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 explaining why you cannot complete the task. Otherwise, calculate the square root and print it. Finish the program by printing the values of int1 and int2.
2. For problem # 1, when the user entered a negative number, you output a message that it was not possible to take the square root of a negative number. This time you will write a Python program that asks 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 (i.e. a number >= 0). Once the user enters a valid number, you calculate and print the square root. Test your program twice, once using a negative number and once using a non-negative number. I JUST NEED ANSWER FOR QUESTION 2 ONLY........... Thank you
import math
n=0
#infinite loop
#until users gives valid number
while(True):
#reading number from user
n=float(input("Enter a non-negative number: "))
#if number is negative,show message
# if is positive break loop
if(n<0):
print("Invalid number..try again")
else:
break
print("Square root: ",math.pow(n,0.5))
Note : Please comment below if you have concerns. I am here to help you
If you like my answer please rate and help me it is very Imp for me