Section 1 of 9

1 Before you start

Before you begin, take a few minutes to check what you already know and how confident you feel. You will see the same questions again at the end of the module — this helps both you and us measure what you have learned. Click an option for every question and confidence rating, then click Next to continue.

Pre-test

What does type(10 / 4) return in Python 3?

Pre-test

What does int("banana") do in Python?

Pre-test

In Python 3, what do 10 / 4 and 10 // 4 evaluate to?

Pre-test

What does 17 % 5 evaluate to in Python?

Pre-test

What does 2 ** 3 + 1 evaluate to in Python?

Pre-test

Which line correctly checks whether patient_age equals 18?

Pre-test

If age is 20 and consent is False, what does age >= 18 and consent evaluate to?

Pre-test

Which line follows Python's standard naming convention for variables?

Pre-confidence

I can explain to a peer the difference between an int and a float in Python.

Not at all confident
Fully confident
Pre-confidence

I can explain to a peer why = and == do different things in Python, and when to use each.

Not at all confident
Fully confident
Pre-confidence

I can choose between `and`, `or`, and `not` to combine two true-or-false conditions in an if statement.

Not at all confident
Fully confident
Section 2 of 9

2 Introduction

Welcome to your first step in Python programming! In this module, where we will cover two building blocks: how Python stores values, and how it combines them.

  • Variables and data types — the names you give to values, and the four basic kinds of value (int, float, str, bool) you will see again and again.
  • Basic operators — the symbols that combine values: arithmetic like + and *, comparisons like == and <, and the words and, or, not for combining true-or-false answers.
Variables, data types and operators in Python.
Variables, data types and operators in Python.

Try every snippet in the Python Scratchpad on the right. By the end of the module you will be able to read a short Python expression, predict what it will print, and explain why.

Section 3 of 9

3 Variables and Data Types

A variable in Python is just a name that points to a value. You make one with a single equals (=) sign: the name on the left, the value on the right.

patient_id = "P-00142"
heart_rate = 88

Python figures out the type of value for you, so you do not have to say up front whether it is a number, some text, or true-or-false.

In this bridging course you will work with four basic kinds of value all the time:

  • int — whole numbers like 42, -7, or 1_000_000.
  • float — decimal numbers like 0.05, 3.14, or 5e-8.
  • str — text wrapped in single or double quotes: "rs429358", 'APOE-e4'. The two quote styles behave the same; pick one and stay consistent.
  • bool — exactly two values, True and False. Note the capital letters; true and false (lowercase) are not valid Python.

You can ask Python which type it gave you with the built-in type() function, and you can convert between types with int(), float(), str(), and bool(). Conversions that do not make sense — like int("banana") — raise an error rather than guessing.

Variables and data types in Python.
Variables and data types in Python.

Try and practise with the following exercise on the Python Scratchpad on the right:

Try it out

Try this snippet in the Python Scratchpad on the right.

Try this snippet
rsid = "rs429358"
p_value = 4.2e-8
is_significant = p_value < 5e-8
samples = 1247
print(type(rsid))
print(type(p_value))
print(type(is_significant))
print(type(samples))

Naming follows a few simple rules.

  • Names use lowercase letters, digits, and underscores.
  • Names must start with a letter or underscore.
  • Names cannot be a Python reserved word like class, def, or return.
  • Naming convention is snake_case for variables and functions: patient_age, p_value_threshold — not patientAge or PatientAge.
  • Choose names that describe the value, not the type.
Section 4 of 9

4 Basic Operators and Expressions

An expression is anything Python can evaluate to a value e.g. 2 + 2, p_value < 0.05, name + " " + surname.

An operator is a symbol that combine values into expressions. They fall into three families — arithmetic, comparison, and logical.

Different operators in Python.
Different operators in Python.
Section 4.1 of 9

4.1 Arithmetic operators

The arithmetic operators are mostly what you would expect from a calculator, with two extras worth knowing:

  • + - * / — addition, subtraction, multiplication, division (division always returns a float)
  • // — floor division: divide and round down, returning an int
  • % — modulo: the remainder after floor division.
  • ** — exponentiation: 2 ** 10 is 1024.

Can you predict the output below?

Predict the output

Read the code carefully and type what you think it will print. Click Submit prediction for AI tutor feedback comparing your prediction against the real output, then click Reveal actual output to run the snippet yourself and see what happens.

Code
print(8 + 3, 8 - 3, 8 * 3)
print(10 / 4)
print(10 // 4)
print(10 % 4)
print(2 ** 10)

Now, for you to try and code some basic operators and expressions.

Try it out

Try this snippet in the Python Scratchpad on the right.

Try this snippet
print(7 + 3)
print(7 - 3)
print(7 * 3)
print(7 / 3)
print(7 // 3)
print(7 % 3)
print(2 ** 10)
Section 4.2 of 9

4.2 Comparison and logical operators

Comparison operators return a bool (boolean i.e. True or False).

The two that catch people out are == (equality, two equals signs) and != (not equal). A single = is assignment, never comparison — confusing the two is one of the most common errors a beginner makes, so go slowly here.

Logical operators combine booleans:

  • andTrue only if both sides are True
  • orTrue if either side is True
  • not — flips True to False and vice versa

Python uses the words and, or, not. Combined with comparisons, they let you write filters that read almost like English: if age >= 18 and consent_given:

age = 17
consent_given = True
if age >= 18 and consent_given:
 print("Patient is eligible for the trial.")
else:
 print("Patient does not meet eligibility criteria.")

Let’s make sure you understand the code logic first.

Parsons problem · Check enrolment eligibility with comparison and logical operators

All the lines you need are in the Line bank on the left — some may be distractors you should leave behind. Drag the lines you need into the Your solution column on the right, in the correct order, then click Check.

Task: Given a patient's age and consent status, print a message only if they are NOT eligible to enrol. The patient is only eligible if their age is 18 or above and has given consent.

Line bank
  • print("cannot enrol")
  • is_eligible = age >= 18 and consent_given
  • if not is_eligible:
  • is_eligible = age = 18 and consent_given
  • consent_given = True
  • is_eligible = age >= 18 or consent_given
  • age = 17
  • if is_eligible = False:
Your solution
  • Drop lines here, in order.

Now, practise writing the code below:

Try it out

Try this snippet in the Python Scratchpad on the right.

Try this snippet
p_value = 0.03
effect_size = 0.42
is_publishable = (p_value < 0.05) and (abs(effect_size) > 0.2)
print(is_publishable)
Section 4.3 of 9

4.3 Operator precedence

When an expression mixes operators, Python applies them in a specific order: ** first, then * / // %, then + -, then comparisons, then not, then and, then or.

When in doubt, use parentheses i.e. ( )— they make your intent obvious to the next person who reads the code, including future you.

Operator precedence in Python.
Operator precedence in Python.

Try to see if can get the right answer!

Predict the output

Read the code carefully and type what you think it will print. Click Submit prediction for AI tutor feedback comparing your prediction against the real output, then click Reveal actual output to run the snippet yourself and see what happens.

Code
print(2 + 3 * 4)
print(2 ** 3 * 2)
print(2 + 3 > 4 and 5)
Section 5 of 9

5 Check your understanding

You have reached the end of the module. Try the same questions again — your answers here, paired with your pre-test answers, are how we measure what the module taught you. Answer every question and confidence rating, then click Submit and see results to view your score.

Post-test

What does type(10 / 4) return in Python 3?

Post-test

What does int("banana") do in Python?

Post-test

In Python 3, what do 10 / 4 and 10 // 4 evaluate to?

Post-test

What does 17 % 5 evaluate to in Python?

Post-test

What does 2 ** 3 + 1 evaluate to in Python?

Post-test

Which line correctly checks whether patient_age equals 18?

Post-test

If age is 20 and consent is False, what does age >= 18 and consent evaluate to?

Post-test

Which line follows Python's standard naming convention for variables?

Post-confidence

I can explain to a peer the difference between an int and a float in Python.

Not at all confident
Fully confident
Post-confidence

I can explain to a peer why = and == do different things in Python, and when to use each.

Not at all confident
Fully confident
Post-confidence

I can choose between `and`, `or`, and `not` to combine two true-or-false conditions in an if statement.

Not at all confident
Fully confident
Section 6 of 9

6 Your results

Here is how your post-test answers compare with your pre-test answers. The pre/post pairing is the most reliable way to see what this module actually taught you.

Your score

Submit the post-test to see your results.

Muddiest point

What is the one thing from this module that is still unclear to you?

Rate this module

Overall, how would you rate this module?

How likely are you to recommend this module to a peer? (0 = not at all, 10 = extremely likely)