Section 1 · Lesson 1
Values, variables and arithmetic
Store values in variables, do arithmetic, and print results.
Python programs work with values (numbers, text, true/false) and store them in variables so you can reuse them.
Variables
campaign = "Summit Search" # a string (text)
clicks = 742 # an int (whole number)
spend = 1288.40 # a float (decimal number)
is_active = True # a bool
A variable is a name pointing at a value. Use lowercase_with_underscores names that say
what the value means; daily_spend beats x.
Arithmetic
| Operator | Meaning | Example | Result |
|---|---|---|---|
+ - * |
add, subtract, multiply | 3 * 4 |
12 |
/ |
divide (always a float) | 7 / 2 |
3.5 |
// |
floor division | 7 // 2 |
3 |
% |
remainder | 7 % 2 |
1 |
** |
power | 2 ** 10 |
1024 |
Underscores in numbers are just for readability: 51_200 is the same as 51200.
Printing and rounding
cpc = 1288.40 / 742
print(cpc) # 1.7363881401617251
print(round(cpc, 2)) # 1.74
print() shows output in the console panel. round(x, n) rounds to n decimals.
Tip: In ad-tech, many key metrics are ratios: CTR = clicks ÷ impressions, CPC = spend ÷ clicks, CPA = spend ÷ conversions. You’ll compute all of them in this course.
Practice
Write your answer, press Run to see results and Check answer to grade it. Shortcuts: Ctrl/⌘ + Enter run, Shift + Enter check.
Click-through rate
DoneA campaign got clicks = 742 from impressions = 51_200. Create a variable ctr holding the click-through rate as a percentage (clicks ÷ impressions × 100), rounded to 2 decimals with round().
Need a hint?
/always gives a float in Python 3.round(value, 2)keeps two decimals.
Practice tasks, quizzes and the certificate are part of the course. The first lesson is free to try.
clicks = 742
impressions = 51_200
ctr = 0
print(ctr)
Files in the working directory
campaigns.csv (40 rows)daily_stats.csv (1,561 rows)customers.csv (300 rows)orders.csv (900 rows)advertisers.csv (12 rows)How long will the budget last?
DoneAn advertiser has budget = 10_000 dollars and spends daily_spend = 650 per day. Set full_days to the number of whole days the budget covers and left_over to the dollars remaining after those days.
Need a hint?
//is floor division;%is the remainder.
Practice tasks, quizzes and the certificate are part of the course. The first lesson is free to try.
budget = 10_000
daily_spend = 650
full_days = ...
left_over = ...
Files in the working directory
campaigns.csv (40 rows)daily_stats.csv (1,561 rows)customers.csv (300 rows)orders.csv (900 rows)advertisers.csv (12 rows)