Learn if-statements, loops, and reusable Python functions.
Learning Objectives
Use if, elif, and else to make decisions.
Use loops to process repeated values.
Define reusable functions.
Understand why functions make quantitative code easier to maintain.
Motivation
Quantitative Python work often repeats the same logic: classify a value, compute a running total, or apply a formula to several inputs. Functions and control flow make that logic explicit.
Conditional Logic
value =-2if value <0: label ="negative"elif value >0: label ="positive"else: label ="zero"label
'negative'
The package includes a small helper with the same logic.
from edumath.python_fundamentals import classify_numberclassify_number(-2), classify_number(0), classify_number(5)
('negative', 'zero', 'positive')
Loops
Loops let us process a sequence of values.
values = [1, 2, 3]total =0for value in values: total = total + valuetotal
6
Functions
A function gives a name to a reusable computation.