2017-09-14 6 views
0

사용자가 숫자를 입력 한 다음 숫자를 사용하여 지수를 만드는 스크립트를 만들려고합니다. 여기 내가 쓰고있는거야. 나는 파이썬 3.6이고 아나콘다/스파이더를 사용하고있다.파이썬에서 지수를 사용할 때 문제가 발생했습니다.

print ("Enter number x: ") 
x = input() 
print ("Enter number y: ") 
y = input() 
import numpy 
numpy.exp2([x,y]) 

그래서 사용자가 x 값을 입력해야합니다. 2. y 값을 입력하십시오. 예를 들어 3. 그런 다음 numpy의 도움을 받아 지수 2를 만듭니다. 3은 8입니다. 대신이 값을 얻습니다.

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 인쇄 (X ' Y')하지만 인쇄 X Y 시도. 그래서 나는이 사이트를 방문하여 https://docs.scipy.org/doc/numpy/reference/generated/numpy.exp2.html#numpy.exp2 그들은 np.exp2를 제안했다. np.exp2 ([x ** y])를 시도했을 때 np가 정의되지 않았으며 numpy 라이브러리를 가져 오지 못했다는 오류 메시지가 표시됩니다. 그래서 지금 numpy.exp2 노력하고 위의 오류가 있어요. 정수로

+1

왜 3.7에있다? 그건 아직 안 끝났어. 나는 심지어 그것의 첫 번째 알파 릴리스가 있다고 생각하지 않습니다. – user2357112

+0

@ user2357112 https://docs.python.org/3.7/whatsnew/3.7.html (오늘 출시 됨) – Artyer

+0

@Artyer : 실제 출시 된 것은 아닙니다. 그것은 사전 알파 문서입니다. 첫 번째 알파는 18 일 (https://www.python.org/dev/peps/pep-0537/)으로 생각합니다. – user2357112

답변

1

변환 문자열 :

import numpy 

print('Enter number x:') 
x = int(input()) 

print('Enter number y:') 
y = int(input()) 

print(numpy.exp2([x, y])) #=> [ 4. 8.] 
+0

@ amnmustafa15 도움이 될 경우 답변을 수락하십시오. –