I'm trying to create a script that allows users to input numbers and then the numbers are used for to create an exponent. Here's what i'm writing. I'm in python 3.6 and using anaconda/spyder.
print ("Enter number x: ")
x = input()
print ("Enter number y: ")
y = input()
import numpy
numpy.exp2([x,y])
so what I want is for the user to enter a value for x. for example 2. then enter a value for y. for example 3. then i'd like (with the help of numpy) create the exponent 2**3 which equals 8. instead i get this.
Enter number x:
2
Enter number y:
3
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/anaconda/lib/python3.6/site-packages/spyder/utils/site/sitecustomize.py", line 880, in runfile
execfile(filename, namespace)
File "/anaconda/lib/python3.6/site-packages/spyder/utils/site/sitecustomize.py", line 102, in execfile
exec(compile(f.read(), filename, 'exec'), namespace)
File "/Users/Ameen/Desktop/assignment1.py", line 16, in <module>
numpy.exp2([x,y])
TypeError: ufunc 'exp2' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''
I tried print ('xy') but that printed xy. so i came across this site https://docs.scipy.org/doc/numpy/reference/generated/numpy.exp2.html#numpy.exp2 they suggested np.exp2. when I tried np.exp2([x**y]) it says np is not defined and an error message saying the numpy library is not imported. so now i'm trying numpy.exp2 and got the error above.