+ 2
Error ' expected in intended block', on line 2
def quiz ( guess, answer): global score if guess == answer: print ('correct answer') score = score + 1 score=0 print "guess the animal" guess1 = input ('questionblahblah') quiz (guess1, 'polar bear')
7 Answers
+ 5
You need to tab in your second in def and tab in if and later second and third in if. You forgot also parentheses for print.
def quiz (guess, answer):
global score
if guess == answer:
print ('correct answer')
score = score + 1
score=0
print ("guess the animal")
guess1 = input ('questionblahblah')
quiz(guess1, 'polar bear')
+ 5
ferhat has already corrected code,
in Python when you are using if else, or any statement that requires a block, etc you need to indent the code for if and else a bit right. in other languages , you have to use {} curlybraces but in Python you have to indent the codes.
+ 4
sorrry for my late reply, i saw your screenshot.
you aren't bringing back the indentation when if ends, just follow Ferhat's code.
, indentation should be only till line 3rd (the lines you want to be executed , when if is true) and after that you need to set back the lines to the original position as when there was if you need to just hit backspace and notepad+ + , or idle will catch it. your code should be like this
This is first line.
if (condition):
indentation for if.
indentation for if
now this is line is continued
since it's not under if.
this way, and i think you meant an else statement there use
overall your code should be
def checkguess(guess, answer):
global score
if(guess==answer):
print("correct answer")
score=score+1
else:
score=score-1
guess1=input("guess the...")
checkguess(guess1, answer)
and make sure to bring back indentation once more, when def checkguess ends as well.
check it, and do notify us, it's working or not. in your code all code was inside if, now it's corrected.
you can also write your code at Sololearn playground, https://code.sololearn.com and give it's link to us.
no need to type in phone you can visit the website in desktop and then copy paste
+ 2
@Ferhat sorry newbie here the parentheses are my fault actually i was typing in PC but typed on phone again. my question is what do you mean by intend.. I don't see any difference between your and my code except those parentheses and it's giving error in line 2
+ 2
intend means to shift lines a bit right, and start it from a bit of space.
this is line
this is line
this is intended line
this is known as intendation
+ 2
@Sandeep my mistake .. it has been corrected but still giving an error
+ 2
@Sandeep I get it now thank you very much but check this once https://i.imgur.com/MzTwh5S.jpg
am I writing my code wrong ? it is still giving me error