2014-02-12 139 views
0

這就是我的代碼,我不知道爲什麼程序會給我那個錯誤.. PD:我是初學者這種編程語言。**或pow()的不支持的操作數類型(s):'str'和'int'

import math 
while True: 
A=input("Escribe el Valor de la 1ra Variable : ") 
B=input("Escribe el Valor de la 2da Variable : ") 
C=input("Escribe el Valor de la 3ra Variable : ") 
Ec1 = (B * -1) 
Ec2 = (B ** 2 - 4 * A * C) 
Ec3 = (2*A) 
R = math.sqrt(Ec2) 
X1 = Ec1 + R/Ec3 
X2 = Ec1 - R/Ec3 
print('''El Valor de Su Ecuacion Es:/n 
X1 = %d 
X2 = %d''' % (X1, X2)) 
+0

[TypeError:不支持的操作數類型爲 - :'str'和'int'](http://stackoverflow.com/questions/2376464/typeerror-unsupported-operand-types-for-str - 和 - int) –

回答

2

由於input()返回一個字符串,所以失敗。要將其轉換爲整數,可以使用int(some_string)

+0

好...我更改int(輸入())的輸入(),但當我這樣做時,R給我其他問題數學域錯誤 – FaustoBaez123

+0

這可能是因爲你試圖採取平方根負數。您需要檢查'Ec2'是否定的,否則'R = math.sqrt(Ec2)'將導致數學領域錯誤。如果'Ec3'等於0,您將會遇到錯誤,這將導致除以零。 –

+0

完美!謝謝你,你真棒!!!!!!!!!該計劃偉大的:) – FaustoBaez123

1

而不是把input("Escribe el Valor de la 1ra Variable : ")

int(input("Escribe el Valor de la 1ra Variable : ")

的輸入轉換爲整數。

相關問題