hands-on labIDE in your browserfree

First Day at Bean There: Your First Python Script

Your first hour as the café's developer: run your first Python script, then greet customers, put today's special on the board, tidy names for cup labels and add up the morning's sales, one Python idea per step.

time
25 min
checked steps
5
level
Beginner
setup
None

Freeone of 170+ labs in Pro

free · no account needed to start

The job

It's your first day as Bean There's developer. The café's till is a small laptop with a terminal, and Sam, who runs the café, has a list of jobs for your first hour: say good morning, put today's special on the board, print tidy names on cups and add up the morning's sales. Each step is one Python idea, and Check tells you straight away whether your script does the job.

5 steps, each checked when you finish it

A check runs your work at the end of every step. Hints and the full solution are there if you get stuck.

  1. 1

    Run your first script

    The dark panel at the bottom is a terminal: you type a command, press Enter and it runs.

    read this step below ↓

  2. 2

    Variables: today's special on the board

    Sam writes a new special on the board every morning.

  3. 3

    f-strings: a price that looks like a price

    Commas in print are quick, but you can't control the spaces or the decimals.

  4. 4

    String methods: tidy names for the cup labels

    Customers type their own names on the order screen, and they type them however they like: " sAM rivera ".

  5. 5

    Numbers: the morning report

    At 11:00 Sam asks how the morning went.

The lab, step by step

The free lab’s own text, every step of it. Hints and solutions stay inside the lab.

Step 1: Run your first script

The dark panel at the bottom is a terminal: you type a command, press Enter and it runs. Python runs right here in your browser, so there's nothing to install. It reads a file of instructions and runs them from top to bottom.

hello.py is open in the editor. It has one line:

print("Hello, world!")

print shows whatever is inside its brackets. The quotes mark a string: a piece of text, kept exactly as you write it.

  1. Press Run. The lab runs python3 hello.py for you, and the terminal shows Hello, world!. You can also type python3 hello.py in the terminal yourself and press Enter.
  2. Sam wants the till to greet customers. Change the words between the quotes to Good morning from Bean There! and press Run again.
  3. Press Check.

Break it on purpose. Delete the closing quote and press Run. Python stops and prints a SyntaxError that points at the line it couldn't read. An error is Python telling you where it got confused, and the last line of it names the problem. Put the quote back before you press Check.

hello.py, the file you edit1 lines
print("Hello, world!")

Step 2: Variables: today's special on the board

Sam writes a new special on the board every morning. If the drink's name is typed into every line of your script, a new special means editing every line. A variable fixes that: it's a name for a value.

special = "Pumpkin spice latte"
price = 3.40

The = means "let this name stand for this value". Text goes in quotes; numbers don't. After these lines, writing special anywhere in the script means "Pumpkin spice latte".

print can show several things at once. Separate them with commas and Python puts one space between them:

print("Today's special:", special)

In board.py, under the variables, write two print lines that show:

Today's special: Pumpkin spice latte
Price: 3.4

Use the names special and price in your prints. Press Run to see the board, then Check. The check changes the variables to another drink and price and runs your script again: a board that follows its variables passes.

Notice the price: you wrote 3.40 and Python shows 3.4. To Python they're the same number, and it drops the zero. Sam won't like that on a price board; the next step fixes it.

board.py, the file you edit7 lines
# The specials board. Sam changes these two values every morning; your prints use them.
special = "Pumpkin spice latte"
price = 3.40

# TODO (Step 2): print two lines that use the variables (don't type the drink or the price here):
#   Today's special: Pumpkin spice latte
#   Price: 3.4

Step 3: f-strings: a price that looks like a price

Commas in print are quick, but you can't control the spaces or the decimals. An f-string gives you both. Put an f right before the opening quote, then put any variable inside curly braces:

print(f"Today's special: {special}")

Python swaps {special} for its value. Inside the braces you can also say how a number should look. :.2f means "two digits after the point":

print(f"£{price:.2f}")      # £3.40

Sam also added a variable for how many cups of the special are left: cups_left = 24.

In board.py, delete Step 2's two prints and write two f-string prints that show:

Today's special: Pumpkin spice latte, £3.40
Cups left today: 24

Press Run, then Check. As before, the check runs your board again with another drink, price and number of cups.

board.py, the file you edit12 lines
# The specials board. Sam changes these values every morning; your prints use them.
special = "Pumpkin spice latte"
price = 3.40
cups_left = 24

# Step 2's board works, but the price shows as 3.4.
print("Today's special:", special)
print("Price:", price)

# TODO (Step 3): replace the two prints above with two f-string prints that show:
#   Today's special: Pumpkin spice latte, £3.40
#   Cups left today: 24

Step 4: String methods: tidy names for the cup labels

Customers type their own names on the order screen, and they type them however they like: " sAM rivera ". The cup label printer needs them tidy.

Strings come with methods, small built-in tools you call with a dot:

MethodWhat it gives back" sAM rivera ". ...
.strip()the text without spaces at either end"sAM rivera"
.upper()all capitals" SAM RIVERA "
.lower()all small letters" sam rivera "
.title()a capital at the start of each word" Sam Rivera "

Methods don't change the original string: they give you a new one. Keep it in a variable, and chain methods one after another:

name = raw_name.strip().upper()

len(name) counts the characters in a string, spaces included.

In label.py, tidy raw_name into a new variable, then print:

SAM RIVERA | Flat White | LARGE
Letters and spaces: 10

The name in capitals, the drink in title case, the size in capitals. You can call a method right inside an f-string's braces: {drink.title()}. Press Run, then Check: the check tries another messy name too.

label.py, the file you edit9 lines
# Names arrive the way customers type them on the order screen. The cup label needs them tidy.
raw_name = "  sAM rivera "
drink = "flat white"
size = "large"

# TODO (Step 4): print two lines:
#   SAM RIVERA | Flat White | LARGE
#   Letters and spaces: 10
# Tidy raw_name first and keep it in a new variable, then use it in both lines.

Step 5: Numbers: the morning report

At 11:00 Sam asks how the morning went. The till counted the cups sold each hour; your script turns them into a report.

Python does arithmetic with the symbols you know, and you can keep each result in a variable:

SymbolMeansExampleResult
+ -add, subtract18 + 4260
*multiply122 * 3366
/divide122 / 430.5
//divide, whole part only122 // 430
total = cups_7am + cups_8am + cups_9am + cups_10am

In report.py, work out the total, the average per hour (four hours) and the takings (cups times the price of a cup), then print exactly:

Morning report
Cups sold: 122
Average per hour: 30.5
Takings: £390.40

Press Run before you format the takings, and look at the number: 122 * 3.20 comes out as 390.40000000000003. Computers store most decimals as a very close binary fraction, and the tiny difference shows up. :.2f hides it on screen. Tills avoid it altogether by counting money in whole pennies: you'll do that in the next quest.

Press Check when the report matches. The check also runs it with another morning's numbers.

What you did in this lab: ran Python in a terminal, printed text, kept values in variables, formatted them with f-strings, tidied strings with methods and did arithmetic. That's Level 1's toolkit, and the boss at the end of the level asks for all of it at once.

report.py, the file you edit12 lines
# The till counted the cups sold each hour this morning. Sam wants the numbers at 11:00.
cups_7am = 18
cups_8am = 42
cups_9am = 35
cups_10am = 27
price_per_cup = 3.20

# TODO (Step 5): work out the total, the average per hour and the takings, then print exactly:
#   Morning report
#   Cups sold: 122
#   Average per hour: 30.5
#   Takings: £390.40

what you get

  • An editor and terminal in your browser
  • A check at the end of every step
  • Hints and the full solution
  • Nothing to install or configure

before you start

  • None. This is the first lab of the Python course.

Part of the Learn Python track

Lab 1 of 15. Learn Python by running a café till: receipts, orders, discounts and the Friday rush. Nothing to install.

Questions about this lab

Do I need to know any Python?

No. This is the first lab of the course. Every step shows the lines you need and explains them.

Do I need to install anything?

No. Python runs right in your browser.

What you do in this lab

You write and run real Python from the first minute, right in your browser: print, variables, numbers, f-strings and string methods, each one used for a job at the café. Every step is checked as you go, and the checker changes your variables and runs your script again, so it knows your script follows them.