Practice: Installing Python on Windows

« Read the chapter

Q1. Join a Windows path

BeginnerCoding

Use the ntpath module to join C:\ , Python313 and python.exe, and print the result.

Goal: Build Windows paths.

Q2. Find the drive letter

BeginnerCoding

Print the drive part of the path D:\code\app.py using ntpath.splitdrive.

Goal: Split a path.

Q3. Version is new enough

IntermediateCoding

Print Version OK if the running Python is 3.10 or newer, otherwise print Too old.

Goal: Check the Python version.

Q4. Build a launcher command

IntermediateCoding

Given major = 3 and minor = 12, print the launcher command py -3.12 script.py using an f-string.

Goal: Use f-strings to build commands.

Q5. Get the file extension

BeginnerCoding

Print the extension of the file name notes.txt using ntpath.splitext.

Goal: Split a file name.

Q6. Output: basename

BeginnerOutput

What does this program print?

Code
import ntpath
print(ntpath.basename("C:\\Users\\Asha\\hello.py"))

Goal: Read path functions.

Q7. Output: escape sequences

IntermediateOutput

What does this program print?

Code
print("C:\\new\\table")
print(len(r"C:\new"))

Goal: Understand backslashes.

Q8. Output: dirname

BeginnerOutput

What does this program print?

Code
import ntpath
print(ntpath.dirname("C:\\a\\b\\c.txt"))

Goal: Read path functions.

Q9. Output: version tuple

IntermediateOutput

What does this program print?

Code
import sys
print(sys.version_info[0] == 3)
print((3, 9) >= (3, 10))

Goal: Compare versions.

Q10. Output: splitdrive

IntermediateOutput

What does this program print?

Code
import ntpath
drive, rest = ntpath.splitdrive("E:\\data\\x.csv")
print(drive)
print(rest)

Goal: Unpack a split path.

Q11. Debug: tab in a path

IntermediateDebugging

The program should print C:\temp\test.txt but prints something strange. Fix it.

Code
print("C:\temp\test.txt")

Goal: Fix escape problems.

Q12. Debug: Python 2 print

BeginnerDebugging

This line was copied from an old tutorial and fails. Fix it.

Code
print "Python is installed"

Goal: Write Python 3 syntax.

Q13. Why tick PATH?

BeginnerConceptual

In two or three sentences, explain why you should tick Add python.exe to PATH.

Goal: Explain PATH.

Q14. What is the py launcher?

IntermediateConceptual

Explain what py does and give one command that picks Python 3.12.

Goal: Understand the launcher.

Q15. Store shortcut problem

IntermediateApplication

A friend types python and the Microsoft Store opens instead of Python. What is the cause and what should the friend do?

Goal: Solve a real setup problem.

Q16. Check several versions

AdvancedApplication

Two versions, 3.11 and 3.13, are installed. Print the command that lists them and the command that runs hello.py with 3.11, each on its own line.

Goal: Choose between versions.