Your first Python program
A temperature converter — a function, a loop, and readable output.
A program that converts a few Celsius temperatures to Fahrenheit and prints them.
Defining a function, returning a value, f-strings, and a simple loop.
Prerequisites
Python installed locally to run it, or just read along — the code is here.
Python is famous for reading almost like plain English. Here is a small, complete program — a temperature converter. Open it in /code to edit, and run it locally to see it work.
def to_fahrenheit(celsius: float) -> float: """Convert a Celsius temperature to Fahrenheit.""" return celsius * 9 / 5 + 32 for c in (0, 37, 100): print(f"{c}°C = {to_fahrenheit(c)}°F")Functions
`def name(args):` defines a reusable unit of work. `return` hands a value back to whoever called it.
def to_fahrenheit(celsius): return celsius * 9 / 5 + 32 print(to_fahrenheit(100)) # 212.0$python main.py0°C = 32.0°F
37°C = 98.6°F
100°C = 212.0°F
Milestone
You wrote and ran a Python program.
A function, a loop, and formatted output — the three things almost every Python script is built from.
More like this
Build your first web page
Hand-write a small, semantic page — a heading, a paragraph, a list — then open the same project in /code and make it yours.
Build a calculator
Most courses teach variables before you have anything to put in one. We are going to skip that pain. We build the calculator first; the concepts show up when the calculator demands them.
Style a card with CSS
The quickest way to feel CSS: take a plain card and give it depth, spacing, and a button — editing the same project the Deep and Reference tiers use.
Liked this one?
Pass it on
Discussion
Be the first to ask
Your questions stay private with the author. The author can pin answers to share with everyone.
Sign in to ask a question privately on this tutorial.
Sign inNo pinned answers yet for this tutorial.