# How to find the exponential value for a number in Python

## How to find the exponential value for a number in Python:

In this post, we will learn how to find the exponential value for a number in Python. The exponential value for a number is calculated by multiplying the same number for a given number of times.

The number is called base number and the number of times it is multiplied to itself is called exponent.

For example, if the base is 3 and exponent is 4, the exponential value will be 3 * 3 * 3 * 3.

We can find the exponential value in different ways in Python. Let’s have a look at them one by one:

## Method 1: By using exponential operator ** :

The exponential operator ** can be used to find the exponential value. We have to use it as like base ** exponent.

Let me show you an example of this operator:

``````base = 2
exponent = 4

result = base ** exponent

print(f'Base: {base}, Exponent: {exponent}, Result: {result}')``````

In this example, we are finding the exponential of a given base and exponent value. If you run this program, it will print the below output:

``Base: 2, Exponent: 4, Result: 16``

### Example with user given values:

We can also take the values as inputs from the user to calculate the exponential:

``````base = int(input('Enter the value of base: '))
exponent = int(input('Enter the value of exponent: '))

result = base ** exponent

print(f'Base: {base}, Exponent: {exponent}, Result: {result}')``````

If you run this program, it will take the base and exponent as inputs from the user and it will print the final result.

``````Enter the value of base: 3
Enter the value of exponent: 4
Base: 3, Exponent: 4, Result: 81``````

### Example with floating point values:

The exponential operator also works with floating point values. For example:

``````base = float(input('Enter the value of base: '))
exponent = float(input('Enter the value of exponent: '))

result = base ** exponent

print(f'Base: {base}, Exponent: {exponent}, Result: {result}')``````

I have changed the above program to take floating point numbers as inputs from the user. It will give output as like below:

``````Enter the value of base: 1.23
Enter the value of exponent: 2.45
Base: 1.23, Exponent: 2.45, Result: 1.6606095188286067``````

## Method 2: By using pow() function:

Python pow() function can be used to find the exponential of a number. It is defined as:

``pow(n, e, m)``
• n is the number or base value.
• e is the exponent value.
• m is a optional number. It is used to calculate the modulus.

We don’t have to calculate the modulus, so we can simply ignore m.

Let’s take a look at the example below:

``````base = int(input('Enter the value of base: '))
exponent = int(input('Enter the value of exponent: '))

result = pow(base, exponent)

print(f'Base: {base}, Exponent: {exponent}, Result: {result}')``````

It is taking the base and exponent values as inputs from the user and finds the exponential by using pow.

If you run this program, it will print output as like below:

``````Enter the value of base: 3
Enter the value of exponent: 4
Base: 3, Exponent: 4, Result: 81``````

It also works with float values:

``````base = float(input('Enter the value of base: '))
exponent = float(input('Enter the value of exponent: '))

result = pow(base, exponent)

print(f'Base: {base}, Exponent: {exponent}, Result: {result}')``````

It will give output as like below:

``````Enter the value of base: 1.23
Enter the value of exponent: 2.45
Base: 1.23, Exponent: 2.45, Result: 1.6606095188286067  ``````

## Method 3: By using math.pow():

math.pow() method is similar to pow(). But it takes only two arguments: the base and exponent value. It is defined as like below:

``pow(b, e)``

Where, b is the base and e is the exponent value. Unlike pow(), math.pow() converts both base and exponent values to float and it returns a float value.

``````import math

base = float(input('Enter the value of base: '))
exponent = float(input('Enter the value of exponent: '))

result = math.pow(base, exponent)

print(f'Base: {base}, Exponent: {exponent}, Result: {result}')``````

It will give similar result.

``````Enter the value of base: 1.23
Enter the value of exponent: 2.45
Base: 1.23, Exponent: 2.45, Result: 1.6606095188286067``````

Now, let me change it to take integer values:

``````import math

base = int(input('Enter the value of base: '))
exponent = int(input('Enter the value of exponent: '))

result = math.pow(base, exponent)

print(f'Base: {base}, Exponent: {exponent}, Result: {result}')``````

We are passing integer values as base and exponent. But the return value of math.pow will be a float:

``````Enter the value of base: 3
Enter the value of exponent: 4
Base: 3, Exponent: 4, Result: 81.0``````

## Method 4: exp() method:

exp method is used to find the exponential of a number with base e. So, for a number n, it will give e^n.

This method is defined in the math module and we have to import math module to use it. For example:

``````import math

print(f'math.exp(2): {math.exp(2)}')
print(f'math.exp(2.3): {math.exp(2.3)}')
print(f'math.exp(-4.3): {math.exp(-4.3)}')``````

It will print:

``````math.exp(2): 7.38905609893065
math.exp(2.3): 9.974182454814718
math.exp(-4.3): 0.013568559012200934``````
{"found_math": false, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 0, "mathjax_display_tex": 0, "mathjax_asciimath": 0, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0, "url": "https://www.codevscolor.com/python-find-exponential-number", "fetch_time": 1653801976000000000, "content_mime_type": "text/html", "warc_filename": "crawl-data/CC-MAIN-2022-21/segments/1652663039492.94/warc/CC-MAIN-20220529041832-20220529071832-00318.warc.gz", "warc_record_offset": 789250940, "warc_record_length": 21058, "token_count": 1471, "char_count": 5273, "score": 3.8125, "int_score": 4, "crawl": "CC-MAIN-2022-21", "snapshot_type": "longest", "language": "en", "language_score": 0.7941163778305054, "file_path": "/sailhome/yjruan/project/latent-lm/data/processed/finemath-4plus/finemath-4plus/train-00008-of-00064.parquet"}