BiTree
  • Search For Lessons
  • Curriculum
  • Pricing
  • For Educators
  • Become a Tutor
  • About
  • Contact
Log InGet Started

Questions, concerns, bug reports, or suggestions? We read every message, write to us at [email protected].

More ways to reach us →
BiTree

Live coding lessons for aspiring developers and security professionals.

[email protected]

(201) 785-7951

Mon–Fri, 9 AM–5 PM EST

Learn

  • Search For Lessons
  • Curriculum
  • Pricing

Company

  • About
  • For Educators & Schools
  • Become a Tutor
  • Contact Us

Legal

  • Terms of Service
  • Privacy Policy
© 2026 BiTree. All rights reserved.
Curriculum/Web Development/Python Logic and Decision Making
40 minBeginner

Python Logic and Decision Making

After this lesson, you will be able to: Write Python code that makes decisions with if/elif/else and repeats actions with for and while loops.

Programs are useful because they can react differently to different inputs. In this lesson you will learn the building blocks of decision-making, comparison, boolean logic, and conditional statements, and how to repeat work efficiently with loops.

Prerequisites:Getting Started with Code

Variables and basic types

A variable is a labeled container for a value. Python figures out the type automatically, integers (1, 42), floats (3.14), strings ("hello"), and booleans (True, False). You assign a value with =, and you can reassign it any time. Variable names should be lowercase and use_underscores.

Comparison and boolean operators

Comparisons return True or False. Combine them with and, or, not.

python
age = 17
is_student = True
print(age >= 16) # True
print(age == 18) # False
print(age >= 16 and is_student) # True
print(not is_student) # False

if / elif / else

Branches let your program react differently based on conditions.

python
score = 87
if score >= 90:
grade = "A"
elif score >= 80:
grade = "B"
elif score >= 70:
grade = "C"
else:
grade = "F"
print("Your grade is: " + grade)

Diagram coming soon!

Flowchart showing diamond decision points: score >= 90? → A; otherwise score >= 80? → B; otherwise → continue

💡 Watch out. Python uses indentation, not braces

Unlike most languages, Python uses indentation (4 spaces is standard) to mark code blocks. If you mix tabs and spaces or indent inconsistently, Python will throw an IndentationError.

for and while loops

Loops repeat a block of code. Use for when you know how many times; while when a condition decides.

python
# Count from 1 to 5
for i in range(1, 6):
print(i)
# Keep guessing until correct
secret = 7
guess = 0
while guess != secret:
guess = int(input("Guess a number: "))
print("You got it!")

Try it: build a simple grade calculator

Write a program that asks for a numeric score and prints the matching letter grade. The score 87 is pre-loaded as input. Pass once the grade is right and your code uses input(), float(), and if/elif/else.

Loading exercise…
Quick Check

What does range(3) produce in a for loop?

Hint: think about whether 3 is included.

Sign in and purchase access to unlock this lesson.

Sign in to purchase
←Getting Started with Code
Back to Web Development
Python Data Structures→