Advanced 10: One-line if
Scenario
You are a data analyst in the Environment team. a if test else b picks one of two values.
Question
Write your code in the editor, press Check my answer, then try changing one small thing.
Your task
- Write your code in the editor
- Press Check my answer
- Look at the result on the right
Advanced · Comprehensions & Data Filtering — question 10 of 30
1. Choose your dataset
Pick an industry and a size. Your code and results change to match.
Advanced 10: One-line if
Write your code in the editor, press Check my answer, then try changing one small thing.
Your code cell is below. Press Check my answer to run the cell — the result appears as Out [1].
💡 Explain my whole code, line by line (hover any word in the editor for a tip)
🌈 In short — no coding words
Altogether: this script runs top to bottom, one line at a time, building up the answer step by step.
Dataset & schema
water_tests
The tiny starter data. Bigger data scrolls.
Fields
| test_id | river | ph |
|---|---|---|
| W1 | Vaal | 7 |
| W2 | Orange | 6 |
| W3 | Vaal | 8 |
| W4 | Tugela | 5 |
Environment data only.
$ Press “Check my answer” — results appear here.Your next steps
Each item turns green when your answer includes it.
- x if ... else y