Bird
Raised Fist0

What is wrong with the following code snippet?

medium📝 Debug Q6 of Q15
Python - Standard Library Usage
What is wrong with the following code snippet?
from datetime import datetime
new_date = datetime(2024, 13, 10)
print(new_date)
AMonth value 13 is invalid; months must be between 1 and 12
BDay value 10 is invalid; days must be between 1 and 9
CThe datetime module does not support creating datetime objects directly
DThe print statement is missing parentheses
Step-by-Step Solution
Solution:
  1. Step 1: Analyze the datetime constructor parameters

    The constructor is called with year=2024, month=13, day=10.
  2. Step 2: Validate the month value

    Months in datetime must be between 1 and 12. Here, 13 is invalid.
  3. Final Answer:

    Month value 13 is invalid; months must be between 1 and 12 -> Option A
  4. Quick Check:

    Month 13 is out of range [OK]
Quick Trick: Months must be 1-12 in datetime constructor [OK]
Common Mistakes:
MISTAKES
  • Assuming day 10 is invalid
  • Thinking datetime module can't create datetime objects directly
  • Confusing print syntax errors

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes