CARVIEW |
Python Random and Datetime Modules
Quiz about Python random and datetim Modules
Question 1
What is the main purpose of using random.seed(5) in a Python script?
To make the sequence of generated random numbers reproducible.
To generate a list of 5 random numbers.
To limit the maximum random value to 5.
To ensure the script always picks the number 5.
Question 2
Which function would you use to select three unique elements from a list?
random.sample(list, 3)
random.shuffle(list, 3)
random.randint(list, 3)
random.choice(list, 3)
Question 3
What is the primary function of the timedelta class in the datetime module?
To format date and time objects into user-friendly strings.
To represent a specific point in time (a timestamp).
To handle time zone information and conversions.
To represent a duration or the difference between two dates or times.
Question 4
How do you get the current local date and time using the datetime module?
datetime.today()
datetime.now()
datetime.utcnow()
date.today()
Question 5
What will be the output of print(date(2025, 7, 26).weekday()) ?
5
6
Saturday
An error will be raised
There are 5 questions to complete.