-1

I am trying to create basic survey program that asks questions and takes a numerical result from the answer and finds the average. i.e. A=10, B=5, C=0. I'm having two basic problems, the first and more important is adding the result to the list. The second is a formatting issue: I keep receiving an 'unexpected indent' or 'indent does match outer indentation layer' error on the append lines. I would appreciate any thoughts.

analyzing simple survey data for political affiliation

voter = list()


def question_1(x):
    if x == "A":   
        print 10
        voter.append(10)   
    elif x == "B":
        print 5
        voter.append(5)
    elif x == "C":
        print 0
        voter.append(0)
    else:
        print "Not a valid answer"
 

def question_2(y):  
    if y == "A":
        print 10
        voter.append(10)
    elif y == "B":
        print 5
        voter.append(5)
    elif y == "C":
        print 0
        voter.append(0)
    else:
        print "Not a valid answer"


def question_3(z):
    if z == "A":
        print 10
        voter.append(10)
    elif z == "B":
        print 5
        voter.append(5)
    elif z == "C":
        print 0
        voter.append(0)
    else:
        print "Not a valid answer"


def question_4(a):
    if a == "A":
        print 10
        voter.append(10)
    elif a == "B":
        print 5
        voter.append(5)
    elif a == "C":
        print 0
        voter.append(0)
    else:
        print "Not a valid answer"


def question_5(b):  
    if b == "A":
        print 10
        voter.append(10)
    elif b == "B":
        print 5
        voter.append(5)
    elif b == "C":
        print 0
        voter.append(0)
    else:
        print "Not a valid answer"


 def get_average():
    average = sum(voter)/len(voter)
    print average 

question_1(raw_input('what is your position on issue 1: A, B, or C'))
question_2(raw_input('what is your position on issue 2: A, B, or C'))
question_3(raw_input('what is your position on issue 3: A, B, or C'))
question_4(raw_input('what is your position on issue 4: A, B, or C'))
question_5(raw_input('what is your position on issue 5: A, B, or C'))

get_average()
Community
  • 1
  • 1
TKB
  • 11
  • 1
  • Exactly what the error is saying you failed at indenting the `def get_average():` you got an extra space infrount the `def` – Taku Feb 26 '17 at 00:39

1 Answers1

0

The only problem in your code is that you got an empty space in frount the def for get_average() the rest works fine. The error tells you what was wrong.

IndentationError means that somewhere in your code you didn't indent correctly. The error is usually followed by red highlights telling you approximately where you got wrong.

Taku
  • 31,927
  • 11
  • 74
  • 85