← Intro to programming with Python
Final projects: temperature table and dice game
Bring loops, functions, formatting and modules together.
You now know the core of programming: values, decisions, loops, collections, functions, errors and modules. Almost every program is just these pieces arranged carefully. These final projects ask you to plan a little, write small functions, and combine them. Take your time, test often, and remember that every programmer looks things up and makes mistakes along the way.
def to_f(c):
return c * 9 / 5 + 32
for c in range(0, 31, 10):
print(f"{c:>4} C = {to_f(c):>5.1f} F"):>4 lines the numbers up on the right, 4 characters wide, so the table looks neat. :>5.1f does the same with one decimal place.
Common mistake: trying to write the whole project at once. Build one piece, run it, then add the next.
Where next? Try changing a project: add a feature, or make it ask the user for its settings.