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
author's image
Abhijeet Pal Author and Editor in Chief @djangocentral

Abhijeet is a full-stack software developer from India with a strong focus on backend and system design. He is driven by the need to create impactful solutions that add value to the internet in any way possible.

LinkedIn Twitter Github

Latest Articles

Latest from djangocentral

Django 4.1 adds async-compatible interface to QuerySet

The much-awaited pull request for an async-compatible interface to Queryset just got merged into the main branch of Django.Pull Request - https://github.com/django/django/pull/14843 The Django core team has been progressively adding async suppor…
Read more →

3 min read

Making Django Admin Jazzy With django-jazzmin

Django admin is undoubtedly one of the most useful apps of Django. Over the years there has been very little change in the admin app as far as the UX is concerned and it's not a bad thing at all. Django admin was designed to provide a simple and minimali…
Read more →

4 min read