Practice: Installing Python on Windows
Q1. Join a Windows path
Use the ntpath module to join C:\ , Python313 and python.exe, and print the result.
Goal: Build Windows paths.
Q2. Find the drive letter
Print the drive part of the path D:\code\app.py using ntpath.splitdrive.
Goal: Split a path.
Q3. Version is new enough
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
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
Print the extension of the file name notes.txt using ntpath.splitext.
Goal: Split a file name.
Q6. Output: basename
What does this program print?
import ntpath
print(ntpath.basename("C:\\Users\\Asha\\hello.py"))Goal: Read path functions.
Q7. Output: escape sequences
What does this program print?
print("C:\\new\\table")
print(len(r"C:\new"))Goal: Understand backslashes.
Q8. Output: dirname
What does this program print?
import ntpath
print(ntpath.dirname("C:\\a\\b\\c.txt"))Goal: Read path functions.
Q9. Output: version tuple
What does this program print?
import sys
print(sys.version_info[0] == 3)
print((3, 9) >= (3, 10))Goal: Compare versions.
Q10. Output: splitdrive
What does this program print?
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
The program should print C:\temp\test.txt but prints something strange. Fix it.
print("C:\temp\test.txt")Goal: Fix escape problems.
Q12. Debug: Python 2 print
This line was copied from an old tutorial and fails. Fix it.
print "Python is installed"Goal: Write Python 3 syntax.
Q13. Why tick PATH?
In two or three sentences, explain why you should tick Add python.exe to PATH.
Goal: Explain PATH.
Q14. What is the py launcher?
Explain what py does and give one command that picks Python 3.12.
Goal: Understand the launcher.
Q15. Store shortcut problem
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
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.