1
所以我試圖做一個數學測驗,3或4秒鐘後問題彈出後,計算機的答案給你,而不是,但如果時間內玩家的答案限制計算機並沒有說出答案。我剛開始在學校編碼爲一個項目...感謝提前在電腦答案設定的時間量後
import time
import random
def computer():
time.sleep(5) #number of seconds the computer waits before answering
print (correct_answer)
#====================================================
from random import randint
number_1 = (randint(0,10)) #random number one
number_2 = (randint(0,10)) #random number two
print(number_1, '+', number_2, "="), #(when i tried to to as an input there was an error)
time.sleep(1) #after one second the question pops up
answer = int(input())
correct_answer = (number_1 + number_2)
if answer == correct_answer:
print ("Correct")
else:
print ("wrong")
由於這個減去
start_time
做的是蟒蛇請正確縮進的代碼,以便我們可以瞭解變量的作用域。 – Bhargav