-4

I'm new to a program called Pythonista. I'm doing a quiz and when I try to test it I get a syntax error.

Here is the error:

enter image description here

j08691
  • 204,283
  • 31
  • 260
  • 272

2 Answers2

2

Your else indentation is not proper at line number 10

your code with proper indentation:

def quiz():
    score  = 0
    begin = raw_input("do you want to start ?")
    if begin == "yes":
        print "A : 56"
        print "B : 48"
        print "C : 45"
        q1 = raw_input("what is 12*4")
        if q1 in ["b","B"]:
            print "congrats !! well done!1"
            score += 1
        else:
            print "sorry!! you are wrong try next one !! good luck"

        print "A : Another ice age"
        print "B : A meteor will hit the earth"
        print "C : Aliens will invade earth"
        q2 = raw_input("what will happen in 50 years?")
        if q2 in ["a","A"]:
            print "nice !! keep going!1"
            score += 1
        else:
            print "sorry!! you are wrong try next one !! good luck"

        return score
    else:
        print "ok bye"
        return 0

This is just an edit on top of your code. But I won't suggest this approach as you are writing same code for both question again and again.Instead of that I will suggest to use one proper data structure and loop through that then it will be dynamic enough to do more quiz.You can use one array of dictionary like this-

[{"question":"what is 5*4 ?","options":[10,20,30],"answer_index":1},{"question":"what is 10*4 ?","options":[40,50,60,30],"answer_index":0}]

Kousik
  • 21,485
  • 7
  • 36
  • 59
1

I'm not familiar with Pythonista, but, from a quick search, it uses significant white-space. In which case, your else is indented when it should be at the same level as its corresponding if. There are further errors like this later on.

See here for more details: http://omz-software.com/pythonista/docs/tutorial/controlflow.html