Practice: History and Features of Python

« Read the chapter

Q1. Print the creator

BeginnerCoding

Write a program that prints the name of Python's creator.

Goal: Recall Python's history.

Q2. Show the major version

BeginnerCoding

Print the major version number of the Python that runs your code.

Goal: Use the sys module.

Q3. Version check message

IntermediateCoding

Print Modern Python if the major version is 3 or higher, otherwise print Old Python.

Goal: Combine version checks with if.

Q4. Years between releases

BeginnerCoding

Python was first released in 1991 and Python 3.0 in 2008. Print how many years passed between them.

Goal: Do simple arithmetic with history facts.

Q5. Dynamic typing demo

IntermediateCoding

Create a variable v = 5, print its type, then give it the value "five" and print its type again.

Goal: Demonstrate dynamic typing.

Q6. f-string sentence

IntermediateCoding

Use an f-string to print: Python was released in 1991. Store the year in a variable.

Goal: Use f-strings.

Q7. Square root with math

BeginnerCoding

Use the math module to print the square root of 81.

Goal: Use the standard library.

Q8. Output: type changes

BeginnerOutput

What does this program print?

Code
a = 7
print(type(a))
a = 7.0
print(type(a))
a = "7"
print(type(a))

Goal: Predict dynamic typing output.

Q9. Output: version comparison

BeginnerOutput

What does this program print?

Code
import sys
print(sys.version_info.major == 3)
print(sys.version_info.major < 3)

Goal: Read comparisons.

Q10. Output: f-string math

IntermediateOutput

What does this program print?

Code
name = "Python"
age = 2026 - 1991
print(f"{name} is about {age} years old")

Goal: Predict f-string output.

Q11. Output: type error handling

IntermediateOutput

What does this program print?

Code
try:
    print("5" + 5)
except TypeError:
    print("cannot add")

Goal: Know that Python checks types.

Q12. Output: match statement

IntermediateOutput

What does this program print? (Python 3.10+)

Code
day = 6
match day:
    case 6 | 7:
        print("Weekend")
    case _:
        print("Weekday")

Goal: Read a match statement.

Q13. Output: math module

BeginnerOutput

What does this program print?

Code
import math
print(math.floor(2.8))
print(math.ceil(2.1))
print(math.pow(2, 3))

Goal: Use math functions.

Q14. Debug: Python 2 print

BeginnerDebugging

This Python 2 style code fails in Python 3. Fix it.

Code
print "Hello"

Goal: Fix Python 2 style code.

Q15. Debug: missing import

IntermediateDebugging

This code fails with a NameError. Fix it so it prints 5.0.

Code
print(math.sqrt(25))

Goal: Remember to import modules.

Q16. Debug: f-string

IntermediateDebugging

The code should print Hello Asha but prints the braces. Fix it.

Code
name = "Asha"
print("Hello {name}")

Goal: Fix a missing f-string prefix.

Q17. Python 2 vs Python 3

IntermediateConceptual

Explain in two or three sentences why people moved from Python 2 to Python 3.

Goal: Explain the Python 2 to 3 change.

Q18. What does dynamically typed mean?

BeginnerConceptual

Explain dynamic typing with a small example.

Goal: Define dynamic typing.

Q19. Why batteries included?

BeginnerApplication

Why do people say Python has batteries included, and how does this help a developer?

Goal: Explain the value of the standard library.

Q20. Pick the right feature

BeginnerApplication

A school wants one script to run on Windows, macOS and Linux computers. Which Python feature helps most?

Goal: Link a feature to a need.