ちょうど2,3時間前にpythonを起動して問題を見つけました。 ブロースニペットは、最初にuserInputを1または2として保存し、その後、ifブロックを実行することを示しています。問題は、コードが(たとえ私がコンソールウィンドウに1を入力したとしても)他の部分にまっすぐジャンプすることです。 私は簡単な間違いをしていますが、どんな助けでも感謝します。 ===具体的にはCPython私のコードはIFブロックをスキップしてELSEに行く
userInput = float(input("Choose 1 (calculator) or 2 (area check)\n"))
if(userInput =='1') :
shape = input("Please enter name of shape you would like to calculate the area for\n")
if(shape == 'triangle') :
base = int(input("Please enter length of BASE\n"))
height = int(input("Please enter HEIGHT\n"))
print("The area of the triangle is %f" % ((base * height)*0.5))
elif (shape == 'circle') :
radius = int(input("Please enter RADIUS\n"))
print("The Area of the circle is %f" % ((radius**2)*22/7))
elif (shape == 'square') :
length = int(input("Please Enter LENGTH\n"))
print("The area of the square is %f" % ((length**2)*4))
else :
initial1 = float(input("Please enter a number\n"))
sign1 = input("please enter either +,-,*,/ \nwhen you wish to exit please type exit\n")
initial2 = float(input("Please enter number 2\n"))
if(sign1 == '+') :
answer = float(initial1) + float(initial2)
print(answer)
elif(sign1 == '*') :
answer = float(initial1) * float(initial2)
print(answer)
elif(sign1 == '-') :
answer = float(initial1) - float(initial2)
print(answer)
elif(sign1 == '/') :
answer = float(initial1)/float(initial2)
print(answer)
PSのVisual Studio 2015で実行されているのPython 3.5を使用して
===。もし可能ならば、私は基本を完全に理解していることを確認したいので、できるだけ基本的な助けをとることができますか?
ありがとうございました! :D
浮動小数点数に変換していますが、文字列と比較しています –