Site icon i2tutorials

Python-Datetime-Quiz

This Quiz contains totally 10 Questions each carry 1 point for you.

1.What will be the output of the following Python code?
import datetime
d=datetime.date(2017,06,18)
print(d)
Error
2017-06-18
18-06-2017
06-18-2017

Correct!

Wrong!

2.What will be the output of the following Python code if the system date is 22nd Jan 2021?
tday=datetime.date.today()
print(tday.weekday())
6
1
4
7

Correct!

Wrong!

3.Which of the following will throw an error if used after the following Python code?
tday=datetime.date.today()
bday=datetime.date(2017,9,18)
t_day=bday-tday
print(t_day.seconds)
print(t_day.months)
print(t_day.max)
print(t_day.resolution)

Correct!

Wrong!

4.What will be the output of the following Python code?
import time
time.asctime()
Current date only
UTC time
Current date and time
Current time only

Correct!

Wrong!

5.The sleep function under the time module is used________
for the specified number of seconds pause the code
In terms of milliseconds, to return the specified number of seconds
Stop the execution of the code
Return the result of the code that had been executed earlier by the specified number of seconds

Correct!

Wrong!

6.State whether true or false.
s = time.time()
t= time.time()
s == t
True
False

Correct!

Wrong!

7.What will be the output of the following Python code?
import time
t=(2020, 11, 8, 9, 15, 12, 6)
time.asctime(t)
‘8 Nov 2020 9:15:12 Sun’
‘2020 8 Nov 09:15:12 Sun’
‘Sun Nov 8 9:15:12 2020’
Error

Correct!

Wrong!

8.The output of both of the print statements is the same, True or False?
import datetime
dt_1 = datetime.datetime.today()
dt_2 = datetime.datetime.now()
print(dt_1)
print(dt_2)
True
False

Correct!

Wrong!

9.What will be the output of the following Python code?
import datetime
d=datetime.date(2016,7,24)
print(d)
Error
2017-07-24
2017-7-24
24-7-2017

Correct!

Wrong!

10.What would be the output of the following Python code?
from datetime import datetime
given_date = datetime(2020, 7, 26)
print(given_date.strftime('%A'))
Monday
Wednesday
Sunday
Error

Correct!

Wrong!

Share the quiz to show your results !

Subscribe to see your results

Ignore & go to results

Python-Datetime-Quiz

You got %%score%% of %%total%% right

%%description%%

%%description%%

Where to go ?

Quizzes

Loading...

Exit mobile version