我正在尝试创建基本的调查程序,询问问题并从答案中获取数字结果并找到平均值。即A = 10,B = 5,C = 0。我有两个基本问题,第一个也是更重要的是将结果添加到列表中。第二个是格式问题:我一直收到意外的缩进'或者'缩进与外部缩进层匹配'附加行上的错误。我很感激任何想法。
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()
答案 0 :(得分:0)
你的代码中唯一的问题是你在get_average()的def
中有一个空格,其余的工作正常。错误告诉你出了什么问题。
IndentationError意味着代码中的某个位置没有正确缩进。错误之后通常会有红色突出显示,告诉您大概出错的地方。