Gerade gestartet Python vor ein paar Stunden und stolpert über ein Problem. Das Blow Snippet zeigt, dass ich zunächst einen userInput als 1 oder 2 speichern und dann einen if-Block ausführen werde. Problem ist, dass der Code direkt in den anderen springt (selbst wenn ich 1 in das Konsolenfenster eintippe). Ich weiß, ich mache einen einfachen Fehler, aber jede Hilfe wird geschätzt.Mein Code überspringt den IF-Block und geht zu ELSE
mit Python 3.5 === in Visual Studio 2015 läuft === speziell CPython
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. Wenn [möglich] könntest du die Hilfe so einfach wie möglich halten, da ich sicherstellen möchte, dass ich die Grundlagen perfekt verstehe.
Danke für die Hilfe !! : D
Sie konvertieren zu einem Float aber Vergleich mit einer Zeichenfolge –