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
2 Answers 2
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
Zahid Khan
3,3952 gold badges29 silver badges40 bronze badges
Sign up to request clarification or add additional context in comments.
1 Comment
Evan Cooper
It seems to be giving me the syntax error in the line 20. Even after the indentation has been fixed.
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
Ahtisham
10.3k6 gold badges49 silver badges62 bronze badges
Comments
lang-py