vendredi 16 avril 2021

Return a random time between two times

I have some trouble with a code in Python. I'm supposed to create a code that generates a random time between 08:00:00 and 20:59:59 and my function should return a time object. I have to use the modules random and datetime. So far i've tried this:

import random
import datetime
def random_time(start, end):
    start = datetime.time(9, 0, 0)
    end = datetime.time(21, 59, 59)
    a = random.random(start, end)
    return a

When I try this it says that "start" is not defined. Am I at least on the right track? :)




Aucun commentaire:

Enregistrer un commentaire