Practice: History and Features of Python
Q1. Print the creator
Write a program that prints the name of Python's creator.
Goal: Recall Python's history.
Q2. Show the major version
Print the major version number of the Python that runs your code.
Goal: Use the sys module.
Q3. Version check message
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
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
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
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
Use the math module to print the square root of 81.
Goal: Use the standard library.
Q8. Output: type changes
What does this program print?
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
What does this program print?
import sys
print(sys.version_info.major == 3)
print(sys.version_info.major < 3)Goal: Read comparisons.
Q10. Output: f-string math
What does this program print?
name = "Python"
age = 2026 - 1991
print(f"{name} is about {age} years old")Goal: Predict f-string output.
Q11. Output: type error handling
What does this program print?
try:
print("5" + 5)
except TypeError:
print("cannot add")Goal: Know that Python checks types.
Q12. Output: match statement
What does this program print? (Python 3.10+)
day = 6
match day:
case 6 | 7:
print("Weekend")
case _:
print("Weekday")Goal: Read a match statement.
Q13. Output: math module
What does this program print?
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
This Python 2 style code fails in Python 3. Fix it.
print "Hello"Goal: Fix Python 2 style code.
Q15. Debug: missing import
This code fails with a NameError. Fix it so it prints 5.0.
print(math.sqrt(25))Goal: Remember to import modules.
Q16. Debug: f-string
The code should print Hello Asha but prints the braces. Fix it.
name = "Asha"
print("Hello {name}")Goal: Fix a missing f-string prefix.
Q17. Python 2 vs Python 3
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?
Explain dynamic typing with a small example.
Goal: Define dynamic typing.
Q19. Why batteries included?
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
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.