Support Our Site

To ensure we can continue delivering content and maintaining a free platform for all users, we kindly request that you disable your adblocker. Your contribution greatly supports our site's growth and development.

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 number 2
Enter the exponent 4
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 ** exponentprint("Result is =",power)

Output

Enter the base number 2
Enter the exponent 5
Result is = 32


PROGRAMS

Latest Articles

Latest from djangocentral

How to Use Subquery() in Django With Practical Examples

In the realm of web development, Django stands as a powerful and versatile framework for building robust applications. One of the key aspects of developing efficient and optimized web applications is handling database queries effectively. In this article…
Read more →

4 min read

DRF Serializer: Handling OrderedDict and Converting It to a Dictionary or JSON

In Django Rest Framework (DRF) tests, when you access serializer.data, you might encounter an OrderedDict instead of a regular dictionary. This behavior is intentional and reflects the design of DRF's serialization process.Understanding the Problem The u…
Read more →

3 min read

Django Rest Framework CheetSheet: Mastering API Development

Django Rest Framework (DRF) is a powerful toolkit that makes building robust and scalable web APIs with Django a breeze. Whether you're a seasoned Django developer or a newcomer, having a comprehensive cheat sheet at your disposal can be a game-changer. …
Read more →

5 min read

How to Perform NOT Queries in Django ORM

In Django, performing NOT queries allows you to exclude certain records from the query results based on specific conditions. The NOT operator, represented by the tilde (~) when used in conjunction with the Django ORM's Q object, helps you construct compl…
Read more →

3 min read