This is a free preview. Enrol on the course to save your progress and open every lesson.

Lesson 3 of 32 · 15 min

Your first program: print, comments and maths

Python runs top to bottom

print("Welcome to Corner Café!")
print("Today's special: banana bread")
print(2 + 3)

Output:

Welcome to Corner Café!
Today's special: banana bread
5
  • print() shows whatever is in the brackets
  • Text goes in quotes — "double" or 'single' both work. Text is called a string.
  • Numbers don't need quotes, and Python can do maths with them
  • Each instruction goes on its own line — no semicolons needed

Printing several things

print("Hours:", 4.5)
print("Shifts this week:", 3, "Total pay:", 337.5)

Output:

Hours: 4.5
Shifts this week: 3 Total pay: 337.5

Separate items with commas and print puts a space between them.

Comments

Anything after a # is a comment — a note for humans that Python ignores.

# Work out the number of minutes in a 4-hour shift
print(4 * 60)  # 60 minutes per hour

Output:

240

Capitals and spelling matter

Python is case-sensitive: print works, Print doesn't. Quotes and brackets must come in pairs.

Try it

Print your name, your favourite food, and how many hours are in a year (365 * 24). Add a comment explaining what your program does.