Engineering

Computer ScienceQ&A LibraryWrite 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

Asked Feb 22, 2020

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.

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) : "))...

Tagged in

Find answers to questions asked by student like you

Show more Q&A

Q: Create a python program for the following: Ask the user to create a username and password. Authentic...

A: When the program is run the user is prompted to enter username and password. Once the username and t...

Q: Either prove the wff is a valid argument through predicate logic or give an interpretation in which ...

A: Proving the wff (well formed formula) of given argument, (∀x)(P(x) ∨ Q(x)) ∧ (∃x)Q(x) → (∃x)P(x)

Q: Hi, I was hoping you can assist me in list the many ways stack is implemented? Hopefully you can pro...

A: Stack: Stack is a LIFO (Last In First Out) type of data structure in which the element, which is pu...

Q: What are the necessary technologies (hardware and software) that need to be implemented in a crm sof...

A: CRM or Customer Relationship Management is used to manage the interaction of customers with the comp...

Q: What is software engineering?

A: Software engineering Software engineering deals with building and maintaining software systems. It ...

Q: gram works correctly. 33. Using the circular doubly linked list below, give the expression correspon...

A: [Note: We’ll answer the first three subparts of the question since the exact one wasn’t specified. ...

Q: Write the following two classes in JAVA Utilizing Java.Util.Scanner when needed. Write a class XXX_C...

A: The two Java programs for the given criteria is as follows, File name: “XXX_Course.java” //Create a ...

Q: I need help with the following Python 3 program: Given a distance (in kilometers) and a finish time ...

A: The below given python program will obey the following rubrics:Importing essential header files.Disp...

Q: What is the difference between Routing and Forwarding?

A: Routing A router is a procedure of choosing path along which the data can be moved from source to th...