Issue
import time
seconds = time.time()
local_time = time.ctime(seconds)
print("Start Time:", local_time)
def bot():
x = 0
while x < 16:
time.sleep(1)
print("Time:", local_time)
x += 1
When I run this code it prints the initial time take before the function every time, I would like it to show the updated time every time local time is printed.
Solution
Using a variable will not re-evaluate it. You'll need to calculate the time again each loop iteration
import time
def bot():
for x in range(16):
time.sleep(1)
seconds = time.time()
local_time = time.ctime(seconds)
print("Time:", local_time)
bot()
Answered By - OneCricketeer
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.