I have been trying out a timer and it keeps printing 0 and i don’t know exactly how to fix it
import time
x=time.time
y=time.time
z=0
b=2
while b<10000:
print b
b=b+10
z=x-y
print z
I think the reason why i keep getting 0 is because i’m doing x-y but if I just leave it
and print x or y it comes up with the totally wrong thing.
Can anyone tell me how to make this work, so at the end it prints how long the program
has been running for, lets say the while loop takes 20 seconds it should print 20 seconds.
Your code never updates y variable after it has been created on 3 line. Place line “y=time.time()” after your loop.
And actually you don’t need a timer, you need programm runtime calculation. Look at – How do you calculate program run time in python?
PS Your example is syntactically incorrect.