2017-09-26 7 views
-7

私は2つの乱数を生成し、ユーザーに答えを促す簡単な減算ゲームを作成しようとしています。 3つの間違ったCONSECUTIVE回答が入力されるまで、プログラムは継続的に質問してほしいです。 whileループを使用してこれをどのように達成できますか?これは私がこれまで持っているものです。continuos while while while python

import random 
import time 

# Count the number of correct answers 
correctCount = 0 

# Count the number of incorrect answers 
incorrectCount = 0 

# Count the number of questions 
count = 0 
numberOfQuestions = 0 

# Get the start time 
startTime = time.time() 

continueLoop = "1" 
while continueLoop == "1": 
# Generate two random single digit integers 
number1 = random.randint(0, 9) 
number2 = random.randint(0, 9) 

# If number1 < number2, swap number1 with number2 
if number1 < number2: 
    number1, number2 = number2, number1 

# Prompt the user to answer what is number1 - number2? 
answer = eval(input("What is " + str(number1) + "-" + str(number2) + "     ? ")) 

# Grade the answer and display the result 
if number1 - number2 == answer: 
    print("You are correct!") 
    correctCount += 1 

else: 
    print("your answer is wrong", number1, "-", number2, "is", number1    - number2) 
    incorrectCount += 1 

# Increase the count of number of questions 
count += 1 

# Get test time 
endTime = time.time() 
testTime = int(endTime - startTime) 
print("The correct count is", correctCount, "out of",   numberOfQuestions,"the testime is", testTime, "seconds") 
+0

を使用して、それを定義し、それはあなたがしようとしていることは何ですか? –

+0

[有効な応答が得られるまでユーザーに入力を求める](https://stackoverflow.com/questions/23294658/asking-the-user-for-input-until-they-give-a-valid-レスポンス) –

+0

'while num_wrong_answers <3:' –

答えて

0

はループ while incorrectCount < 3: としてこれを使用して試してみて、メインループとしてそれを使用するか、またはdef mainloop(incorrectCount, correctCount):