Bird
0
0

This code tries to use the datetime module but causes an error:

medium📝 Debug Q14 of 15
Python - Standard Library Usage
This code tries to use the datetime module but causes an error:
print(datetime.date.today())

What is the fix?
AAdd <code>import datetime</code> before using it
BChange <code>date.today()</code> to <code>today.date()</code>
CUse <code>from datetime import date</code> and then call <code>date.today()</code>
DNo fix needed, code is correct
Step-by-Step Solution
Solution:
  1. Step 1: Identify the cause of the error

    The code uses datetime.date.today() without importing the datetime module, causing a NameError.
  2. Step 2: Fix by importing the module

    Adding import datetime at the top allows access to datetime.date.today().
  3. Final Answer:

    Add import datetime before using it -> Option A
  4. Quick Check:

    Missing import causes error = fix by importing [OK]
Quick Trick: Always import modules before using their functions [OK]
Common Mistakes:
  • Forgetting to import the module
  • Changing function names incorrectly
  • Assuming code works without import

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes