int()
またはを使用float()
して、ユーザーからの入力数値を整数/浮動小数点数に変換し、数式をそれらに適用する必要があります。
need == "pythagoras" or "Pythagoras"
と同等です:
(need == "pythagoras") or "Pythagoras"
したがって、need
等しい場合"pythagoras"
、これはTrue
else return "Pythagoras"
(つまり、True 値) を返します。つまり、入力が何であれ、if
条件は常に変わります。True
作業コード:
need = raw_input("What do you need to Use?")
#use a while loop loop, this will continuously ask for the user input
#until he doesn't enters a corrects one.
while need.lower() != "pythagoras":
print "Invalid choice! try again"
need = raw_input("What do you need to Use?")
pythagoras = raw_input("What side do you Need?")
if pythagoras.lower() == "hypotenuse":
k1 = int(raw_input("Known Side 1: ")) #use int() to convert the user input to integers
k2 = int(raw_input("Known Side 2: ")) # use float() if you want floats
print (k1**2 + k2**2)**0.5 # now apply the formula