2017-08-11 72 views
0

我正在製作遊戲。在這個遊戲中,用戶被問到一個問題。如果他得到它的權利,它會進入right_answer列表並進入答案列表。如果他弄錯了,它會進入答案列表。再加上他們得到正確答案的每一個正確的問題。它將成爲8個問題,每一個都是一個功能。這是第一個問題。問題是它沒有打印任何東西。如何將列表返回給函數外的另一個列表

def question_one(answer,right_answer,points): 
answer = [] 
right_answer = [] 
print "how would you write this question in code so it would print" 
answer=raw_input("< ") 
#this is if he gets it right 

if answer=="""print "how would you write this question in code so it would 
print""""": 
#this is where the answers are inserted into the lists 
    right_answer.append(answer) 
# this is where the answer goes that they gave 
    answer.append(answer) 
    points=points+1 
#this is if he gets it wrong 
else: 
    answer.append(answer) 
#this is to return the values and the lists for the right answer and the 
answer 
    return answer,right_answer,points  
(answer.append(answers),correct_answer.append(correct_answers), points)=question_one(answers,correct_answers,points) 
+0

不能分配給'append'呼叫或任何其他功能或方法調用。 – user2357112

+0

你能澄清一點嗎?我很困惑,你在最後一行代碼 – Mangohero1

+0

上試圖找到你的答案字符串是無效的。你想''「」打印「你如何在代碼中編寫這個問題,以便打印\」「」「''或''''print'如何在代碼中編寫這個問題,以便打印出'''''如果你想使用雙引號,你必須跳過最後一個。 – TemporalWolf

回答

1

我不是你想實現什麼100%,但在這裏是爲我的作品你的代碼的近似值:

def question_one(answer, right_answer, points): 
    ''' 
    The user is asked a question. 
    If the answer is incorrect, it goes into the answer list. 
    If the answer is correct, it goes into the right_answer list. 
    ''' 
    answer_list = [] 
    right_answer = [] 
    print("What is 1 + 1?") 
    answer = input() 

    if answer == '2': 
     right_answer.append(answer) 
     answer_list.append(answer) 
     points += 1 
    else: 
     answer_list.append(answer) 

    return answer_list, right_answer, points 
+0

請記住這個人使用'python2'。'input'應該是'raw_input' :-) – Mangohero1

相關問題