0

I'm currently working on some python code but its giving me a syntax error in the second 'if statement'. When I run it, it highlights quadpos. What seems to be the problem?

print(' Hello, press enter to continue')
print('What is your A value?') # Asking for the A value
myA = input()
myA = int(myA)
print('What is your B value?') # Asking for the B value
myB = input()
myB = int(myB)
print('What is your C value?') # Asking for the C value
myC = input()
myC = int(myC)
quad = ((myB * myB) - (4 * myA * myC))
if int(quad) < int(0):
 print('Cannot process Value')
else:
 quad2 = (int(quad)**(1/2.0))
 if int(myA) > int(0):
 quadneg = ((int(-myB) - int(quad2)) / (2 * myA) 
 quadpos = ((int(-myB) + int(quad2)) / (2 * myA)
 print(int(quadneg))
 print(int(quadpos))
 else:
 quad3 = ((int(-myB) * int(-myB)) + int(quad2)) / (2 * myA) 
 print (int(quad3))
Karl Knechtel
61.5k14 gold badges134 silver badges194 bronze badges
asked Nov 19, 2017 at 5:35
0

2 Answers 2

1

The error is in the line 21 and 22 according to your attached picture

print( int( quardneg) )
print( int(quardpos) )

followed by else statement

The syntax of if else statements are :

If condition:
 Code...
Else 
 Code ..

You are doing:

 If condition:
 Code
 Code -- Error is here
 Else 
 Code.

You can't put the code in the same indentation of if statement, if you do so then you have to replace else by next if.

answered Nov 19, 2017 at 5:48
Sign up to request clarification or add additional context in comments.

1 Comment

It seems to be giving me the syntax error in the line 20. Even after the indentation has been fixed.
1

You seem to have a missing bracket.

quadneg = ( (int(-myB) - int(quad2)) / (2 * myA) )
quadpos = ( (int(-myB) + int(quad2)) / (2 * myA) ) 
answered Nov 20, 2017 at 21:55

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.