Bird
Raised Fist0

You want to create a path for a file named 'report.txt' inside a user's documents folder, which is stored in variable user_docs. Which code correctly creates the full path?

hard🚀 Application Q8 of Q15
Python - Standard Library Usage
You want to create a path for a file named 'report.txt' inside a user's documents folder, which is stored in variable user_docs. Which code correctly creates the full path?
Afull_path = os.path.join('report.txt', user_docs)
Bfull_path = user_docs + '/report.txt'
Cfull_path = os.path.join(user_docs, 'report.txt')
Dfull_path = os.path.join(user_docs + 'report.txt')
Step-by-Step Solution
Solution:
  1. Step 1: Use os.path.join with separate arguments

    Pass folder and file as separate arguments to join for correct path.
  2. Step 2: Avoid string concatenation or wrong argument order

    Concatenation may cause wrong separators; order matters for correct path.
  3. Final Answer:

    full_path = os.path.join(user_docs, 'report.txt') -> Option C
  4. Quick Check:

    Join folder and file separately [OK]
Quick Trick: Join folder and file as separate arguments [OK]
Common Mistakes:
MISTAKES
  • Concatenating strings manually
  • Swapping argument order

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes