dimanche 26 février 2017

Strange (for me) Syntax Error with If|Elif|Else Statements [on hold]

I am programming a little Python 3.5 program in Spyder3 on Ubuntu 16.10 that can calculate vertexes and so on of parabolas ... The code ...

# Enter the code of enter
entercodeinput = input("Enter the code of enter of the formula: ")
entercode = int(entercodeinput)

# Entercode 1 , Roots and y-intercept
if 1 == entercode:
    print("1: Roots and y-intercept")

    inputa = input("a = ")
    a = int(inputa)

    inputb = input("b= ")
    b = int(inputb)

    inputc = input("c= ")
    c = int(inputc)

    xrealminus = -2*c / b - math.sqrt(b**2 - 4*a*c)
    xrealplus = -2*c / b + math.sqrt(b**2 - 4*a*c)
    ximagminus = -2*c / b - cmath.sqrt(b**2 - 4*a*c)
    ximagplus = -2*c / b + cmath.sqrt(b**2 - 4*a*c)
    print("Real minus solution: ",      xrealminus)
    print("Real plus solution: ",      xrealplus)
    print("Imaginary minus solution:", ximagminus)
    print("Imaginary plus solution:", ximagplus)

# Entercode 2 , Vertex
if 2 == entercode:
    print("2: Vertex")

    inputa = input("a = ")
    a = int(inputa)

    inputb = input("b= ")
    b = int(inputb)

    inputc = input("c= ")
    c = int(inputc)

    x = -b / 2*a
    y = -1*(b**2 - 4*a*c)/4*a

    print("x-component of vertex: " , x)
    print("y-component of vertex: " , y)    

# Entercode 3 , Axis of symmetry
if 3 == entercode:
    print("3: Axis of symmetry")

    inputa = input("a = ")
    a = int(inputa)

    inputb = input("b= ")
    b = int(inputb)

    x = -b / 2*a

    print("Solution", x)

# Entercode 4 , Focus  
if 4 == entercode:
    print("4: Focus")

    inputa = input("a = ")
    a = int(inputa)

    inputb = input("b= ")
    b = int(inputb)

    inputc = input("c= ")
    c = int(inputc)

    x = -b / 2*a
    y = 1--1(b**2 - 4*a*c)/4*a

    print("x-component of vertex: ", x)
    print("y-component of vertex: ", y

# Entercode 5 , Directrix    
if 5 == entercode:
    print("5: Directrix")

    inputa = input("a = ")
    a = int(inputa)

    inputb = input("b= ")
    b = int(inputb)

    inputc = input("c= ")
    c = int(inputc)

    y = -1 * -1*(b**2 - 4*a*c) / 4*a
    print("Solution:", y)

# 42
if 42 == entercode:
    print("""The answer of the life, the universe and everything ...
... is here not needed! ;-""")

# No right input
entercodes = (1,2,3,4,5,42)

if not entercode in entercodes:
    print("Invalid input! Please run QPyES again!")

In line 136 or if 5 == entercode: Spyder3 is showing me there should be an error ... I didnt´t know why, because the if-Statements before are errorless ... When I comment the full 5th if-Statement, the error go to if 42 == entercode: and so on ...

Can you please help me? I don´t know next ... I tried to run it errorless with replacing if 1 == entercode: and elif 2 == entercode: and so on until else: but thats not made it ...

Thank you very much!

Jakob Krieger

Aucun commentaire:

Enregistrer un commentaire