Chapters
Python114 chapters

Exercises

os and sys

3 tasks. Write the code, press Check, and the page runs it against a real Python interpreter.

Exercise 1

Read a setting from the environment, falling back to a default.

Python
import os

os.environ["APP_MODE"] = "demo"
# print APP_MODE, then a missing one with the default "unset"
Exercise 2

Create the nested folder without failing when it already exists, then confirm it.

Python
import os
# make data/reports twice, then print whether it is a directory
Exercise 3

Split the filename into its stem and extension.

Python
import os

name = "march.csv"
# print ('march', '.csv')