Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Math Module import
#1
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
Reply
#2
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
Reply
#3
what does this mean?
C:\
λ ptpython

I have a syntex error by running this code
Reply
#4
(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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  please help me convert this formula via the math module tinx_ss 1 350 Apr-10-2024, 12:51 AM
Last Post: deanhystad
  How to create simple thread safe singletone that protect __init__ on import module umen 0 1,689 Apr-16-2020, 09:43 AM
Last Post: umen
  Import Python file with a name of a module in Stantard Library tiago_code 7 3,220 Dec-11-2019, 06:08 AM
Last Post: ICanIBB

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020