-1
我正在嘗試創建一個基本的調查程序,它提出問題並從答案中獲取數字結果並查找平均值。即A = 10,B = 5,C = 0。我有兩個基本問題,第一個也是更重要的是將結果添加到列表中。第二個是格式問題:我在附加行上不斷收到'意外縮進'或'縮進符合外部縮進層'的錯誤。我會很感激任何想法。如何在python中附加if語句的結果
分析簡單的調查數據,政治面貌
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()
確切地說,錯誤是說你在縮進'def get_average()時失敗了:'你有一個額外的空間infrount'def' – abccd