0
How to record time?
I’m making my first basic game with the little knowledge I have of python, and want to incorporate a feature that tells the user how much time it took them to complete the game, how would I go about doing this? Also I’d like to make a time trial mode, is there a way to stop the program as soon as a timer reaches zero?
11 Antworten
+ 1
So I analayzed your code and it just worked finde. The own problem was, you have to take start = time.time() delete it and type it before "while guess != rng" without indentations . Please contact me on solo learn to be little faster. I wanna really help you out
+ 1
One way is to use perf_counter.
You can see an example for how to set it up in this code (lines 1017 and 1037):
https://code.sololearn.com/cLDkFpQaT06p/?ref=app
+ 1
Simple:
import time
Start = time.time()
User = input("")
End = time.time() - Start # difference
print("it took you", end, "seconds to type", User)
+ 1
William M That worked! thank you so much you were a great help :)
+ 1
No problem you are welcome any time
0
William M This works, but it gives me 10+ decimal points when it prints, how can i shorten this to two decimals?
0
import time
Start = time.time()
User = input("")
End = time.time() - Start # difference
print("it took you", round(End, 2), "seconds to type", User)
0
Just changed in print (round(End,2)) to round it on two digits after the comma.you can also print it as whole number just delete the 2
0
William M When i try this, i get an error ‘float’ object can not be interpreted as an integer
0
Can you give me a link or a copy of your code. I posted the code after I tried it and it worked.
0
William M
https://repl.it/@Chromal/count
This doesnt work on sololearn but works on the website link. The last line(line 103) is where i have round(end,2)