r.REZA/NOZADI
فا
LEARN / PRACTICE / REPEAT

Your first Python steps: from data to decisions

Learn variables, conditions and functions with a small robot decision-making example.

Lesson progress0 / 2
01 / STUDY1 / 2

Variables & conditions

Install Python 3 and create a file named robot.py. This educational example prints a decision and does not control real hardware.

Data and conditions

A variable names a value. An if statement chooses a path through your program. Indentation is part of Python syntax; use four spaces inside each block.

distance_cm = 18

if distance_cm < 20:
    print("STOP")
else:
    print("MOVE")

Turn the logic into a function

A function lets you repeat the same decision for different inputs. This function returns STOP below 20 and MOVE otherwise. The for loop tests three distances.

def decide(distance_cm):
    if distance_cm < 20:
        return "STOP"
    return "MOVE"

for distance in [10, 20, 35]:
    print(distance, decide(distance))
Enroll for free to practice ↗
02 / YOUR TURN

Learning ping-pong

⌑ Practice unlocks after you mark this section as studied.

LEARNING COPILOT

✦ Your AI learning companion

Ask for a simpler explanation, another example or a hint.

Instructor’s hint

18 is below the threshold of 20.

The tutor is available to enrolled students.

OUTPUTINTERACTIVE PORTFOLIO SHELL
⌘ reza-shell
✓ Workspace ready. Type to explore.
⌕
Build. Discover. Share.PAGE ↵Curiosity is where it starts.PAGE ↵Python Developer & Robotics ProgrammerPROJECT ↵Dofamin Music Academy Website, Full-Stack Web DeveloperPROJECT ↵PolyShine website, WordPress Web DeveloperPROJECT ↵Dofamin telegram bot, PHP DeveloperPROJECT ↵Experience, built in the real world.PAGE ↵My problem-solving toolkit.PAGE ↵From idea to execution.PAGE ↵Every bug has a discovery story.PAGE ↵Learn. Experiment. Build.PAGE ↵Build your next skill.PAGE ↵Let’s start a conversation.PAGE ↵The complete resume.PAGE ↵How the web talks: an introduction to HTTPTUTORIAL ↵Your first Python steps: from data to decisionsTUTORIAL ↵Your first safe query with PHP and PDOTUTORIAL ↵Understanding IDOR: an identifier is not permissionTUTORIAL ↵Build a small WordPress pluginTUTORIAL ↵Git from zero: your first project historyTUTORIAL ↵Web development foundations: PHP & WordPressCOURSE ↵Python basics and the developer toolkitCOURSE ↵Web access control: a safe starting pointCOURSE ↵
Pages, courses, tutorials and writeupsEsc