inochi
Member
- Your Task History ID
- IjU3NmQwNTZlMDYzNzA0MzQ1MjZiNTUzNCI_3D_pc
Hello,
after updating Python & Javascript Code, I can no longer get the codes I had before to work.
I give an example just to understand:
I would use this code to randomly generate the hours and minutes and then the output would return with the random numbers. Example: 1 hour and 30 minutes ago.
After updating, most of the code gives me an error.
In this particular case, with this code I posted, I get the error:
How can I solve it?
Thank you
after updating Python & Javascript Code, I can no longer get the codes I had before to work.
I give an example just to understand:
import datetime
import random
now = datetime.datetime.now() # ottieni l'orario corrente in Italia
delta = datetime.timedelta(minutes=random.randint(10, 60)) # genera un intervallo casuale tra 10 e 60 minuti
random_time = now - delta # sottrai l'intervallo casuale all'orario corrente per ottenere un orario casuale precedente
time_diff = now - random_time
hours_diff = time_diff.seconds // 3600
minutes_diff = (time_diff.seconds // 60) % 60
if hours_diff == 0:
time_ago = f"{minutes_diff} minuti fa"
elif hours_diff == 1:
time_ago = f"1 ora e {minutes_diff} minuti fa"
else:
time_ago = f"{hours_diff} ore e {minutes_diff} minuti fa"
output = [{"random_time": time_ago}]
print(output)
I would use this code to randomly generate the hours and minutes and then the output would return with the random numbers. Example: 1 hour and 30 minutes ago.
After updating, most of the code gives me an error.
In this particular case, with this code I posted, I get the error:
"name 'random_time' is not defined"
How can I solve it?
Thank you
Attachments
-
Screenshot del 03-01-2024 alle [email protected]38 KB · Views: 45