Python Forum

Full Version: Math Module import
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi there,
I am a new python user and I am learning python in my uni. I got stuck with my homework. I have to import a math module into python. This is my task:

Use the math module to calculate e to the power of 3. print the answer.

This is my code:
import math.exp(x)
x= 3
print(math.exp(x))

But this doesn't work....

I don't understand, how can I import the math.exp module from here: https://docs.python.org/3/library/math.html

any ideas?

Thanks!
Jack
You most import math module.
C:\
λ ptpython
>>> import math

>>> x = 3
>>> math.exp(3)
20.085536923187668
REPL like ptpython, IPython ,you get autocomplete so when type math. you see all modules in math.

As a script:
import math

x = 3
print(math.exp(3))
Output:
20.085536923187668
what does this mean?
C:\
λ ptpython

I have a syntex error by running this code
(Apr-30-2018, 01:10 PM)Jack_Sparrow Wrote: [ -> ]C:\
λ ptpython
It's just my starting ptpython(REPL) from cmder.
You don't need it,i don't know what you use.
If you use IDLE that comes with Python.
>>> import math
 
>>> x = 3
>>> math.exp(3)
20.085536923187668
Python has interactive way run code then you see >>>.
In a script there is no >>> as you see in my second code.