我对Python相当陌生,已经创建了一个小测验,将问题/答案链接到txt文件并存储高分。在
编辑我没有使用PYGAME
我想设定回答问题的时间限制,例如1分钟。我设法让计时器倒计时,但它倒计时,然后继续我的比赛。在
有没有办法让它并排运行?我想了一个while循环,但它把它搞砸了,所以我猜我做错了。。。在
这是我的代码(好吧,最上面的部分):import linecache
import sys
import pickle
import time
def countdown():
t = 60
while t:
mins, secs = divmod(t, 60)
timeformat = '{:02d}:{:02d}'.format(mins, secs)
print(timeformat, end='\r')
time.sleep(1)
t -= 1
print('You're out of time!\n')
def travel():
i = 0
countdown()
name = input("What is your name: ")
q1 = linecache.getline("travel.txt", 1)
a1 = linecache.getline("travel.txt", 2)
b1 = linecache.getline("travel.txt", 3)
c1 = linecache.getline("travel.txt", 4)
print("\n", q1, a1, b1, c1)
q = input("Answer: ")
if q == "b":
print("Correct! You've scored 1 point.")
i += 1
else:
print("Wrong answer buddy, 0 points.")