我試圖創建一個程序來執行正弦規則,但是我得到上面的錯誤,我檢查了其他問題,但是我無法理解它。Python - Easy - TypeError:無法乘以類型'float'的非int的序列
import math
PI = math.pi
x = raw_input ("To get length please enter 1, to get angle please enter 2 : ")
while x:
if x == "1":
print ("This is to find a length using the Sine Rule")
A= str(raw_input ("what is angle A? "))
a= str(raw_input ("what is length a? "))
B= str(raw_input ("what is angle B? "))
b = (a/math.sin((PI/180)*A)) * (math.sin((PI/180)*B))
print (' your answer is : ', b ,'cm')
raw_input ("press <enter> to end")
if x == "2":
print ("This is to find an angle using the Sine Rule")
A= float(raw_input ("what is angle A? "))
a= raw_input ("what is length a? ")
b= raw_input ("what is length b? ")
B = (math.sin((PI/180)*A)/a) * b
print (' your answer is : ', B ,'degrees')
raw_input ("press <enter> to end")
'raw_input()'已經返回字符串。你爲什麼在他們周圍有'str()'?你可能想要做'float()'。 – 2012-03-09 22:37:25