5 Antworten
+ 9
Store whatever value that you want to print into a variable as a string, and use a for-loop. After each second, add the number (as a string) to the string, and reprint it.
+ 5
You cant do that here as you code is executed on sololearns servers and the result returned and printed to screen you wont be able to see it refresh replacing the previous number with a new one.
+ 1
can anybody share code for this??
+ 1
import os
import time
timer = 10
while timer > 0:
os.system("cls")
print(timer)
timer -= 1
time.sleep(1)
thats just for the timer.
You might want to look into threading and getch to allocate the timer "outside" the quiz.
since timer will refresh the shell every second you need single keypress listener for every question in the quiz to check if the person answering presses the correct key within the period of less than a second
0
if you are using shell to run this you need to import
threading
getch from msvcrt
time
and you need to make it as a multiple choice quiz.
also you could import os
and do os.system("cls"), to make the countdown stay in same place and just count numbers down.