5 Antworten
+ 8
Yes, that was just a demo. The code displays the current time at each loop iteration. The loop itself takes some time tobe processed (loops are *really* slow), this is why you get fractions of seconds piling up.
In a game you probably need to take time.time(), constantly checking the current time and increasing a stopwatch indicator as soon as the time difference exceeds one second.
https://code.sololearn.com/ckBSI6ceZv2z/?ref=app
+ 6
You can use 'time' module:
https://code.sololearn.com/c2mzXdMavZfi/?ref=app
+ 2
import time
seconds=0
while True:
time.sleep(1)
seconds+=1
print(seconds, end='\r')
+ 1
Kuba Siekierzyński thanks for your help, only, when i change it to 30 seconds it outputs this:
0.0
1.0
All the way to 10.0 as it should
11.1
12.1
13.1
All the way to 29.1
+ 1
Kuba Siekierzyński thanks, i just changed the 1f at the end to 0f to make it return an integer, then realised i could just remove the print so no one would know. It is only a 3 minute timer so shouldn't make a difference. Thanks for your help