2017-08-11 4 views
0

私はゲームを作っています。このゲームでは、ユーザーに質問があります。彼がそれを正しく得るなら、それはright_answerリストに入って、答えリストに行きます。彼はそれが間違っている場合は、答えのリストに入る。プラス彼らは正しい正しい質問ごとにポイントを得る。その8つの質問になると、それぞれが関数です。これは質問番号1です。問題は何も印刷しないということです。関数外のリストにリストを返す方法

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 'をしたいでしょう。この質問をコードに書くと、\" "" '' '' print' "という印字ができます。 Pythonは4つの ''を一緒に誤って解釈するので、二重引用符を使用する場合は、最後のものをエスケープする必要があります。 – 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

関連する問題