Python Program to Calculate Power of a Number

1 min read

Problem Definition

Create a Python program to take two numbers from the user one being the base number another the exponent then calculate the power.

Program

import math

base_number = float(input("Enter the base number"))
exponent = float(input("Enter the exponent"))

power = math.pow(base_number,exponent)
print("Power is =",power)

Output

Enter the base number2
Enter the exponent4
Power is = 16.0

The built-in math module provides a number of functions for mathematical operations. The pow() method takes a base number and exponent as parameters and returns the power.

Since in Python, there is always more than one way of achieving things calculating power with the exponentiation operator is also possible. The exponentiation operator x**yevaluates to power.

Program

base_number = int(input("Enter the base number"))
exponent = int(input("Enter the exponent"))

power = base_number ** exponent
print("Result is =",power)

Output

Enter the base number2
Enter the exponent5
Result is = 32

PROGRAMS

Latest Articles

Latest from djangocentral

Capturing Query Parameters of request.get in Django

In Django, the request object contains a variety of information about the current HTTP request, including the query parameters. Query parameters are a way to pass additional information in the URL and are used to filter or sort data. The request object p…
Read more →

2 min read

Understanding related_name in Django Models

In Django, related_name is an attribute that can be used to specify the name of the reverse relation from the related model back to the model that defines the relation. It is used to specify the name of the attribute that will be used to access the relat…
Read more →

2 min read