[Tutor] Calculate 4**9 without using **
Whom Isac
wombingsac at gmail.com
Sat Mar 4 18:05:03 EST 2017
Hi there. So if you want to make a function for exponent (e^x) rather than power such as x**n, then you need to use/import pythons math module such as Numpy.
Use:
import numpy as np
List = [1,2,3,4,5....]
np.exp(list)
This would give exponential value of each x in the list.
If you want to just power by a certain base then use:
def powerBase(base,n):
return base**n
Example print(powerBase(2,3)) should give you 8.
That should also do that for you.
On Mar 5, 2017, 3:37 AM, at 3:37 AM, Sri Kavi <gvmcmt at gmail.com> wrote:
>Hi,
>
>
>I'm a beginner learning to program with Python. I'm trying to explain a
>solution in plain English. Please correct me if I'm wrong.
>
>
>Create a function that takes base and exponent as arguments.
>
>
>
>In the body of the function:
>
>set a result variable to the base.
>
>
>
>User a for-loop with a range of 1 to the exponent.
>
>With each iteration, set the result to the product of result times
>base.
>
>
>
>After the loop, return the result.
>
>
>
>Call the function.
>
>
>
>
>
>Regards
>Sri
>_______________________________________________
>Tutor maillist - Tutor at python.org
>To unsubscribe or change subscription options:
>https://mail.python.org/mailman/listinfo/tutor
More information about the Tutor
mailing list