Making Decisions - Bryantad/Sona GitHub Wiki

🔄 Making Decisions - Your Program's Brain

Welcome to Decision Making! 🧠

Perfect for all ages 12-55+ - This guide shows you how to make your programs smart by teaching them to make decisions. Whether you're a visual learner, need step-by-step explanations, or learn best through examples, we've got you covered!


🎯 What You'll Learn

By the end of this guide, you'll be able to:

  • ✅ Use when statements to make decisions
  • ✅ Compare values with different operators
  • ✅ Handle multiple conditions and complex logic
  • ✅ Build programs that respond intelligently
  • ✅ Debug decision-making errors with confidence

🌟 The Basic Decision: when

The when statement is like asking a question and doing something based on the answer:

think "Checking if someone can vote"
age = 18

when age >= 18:
    show "You can vote!"
    show "Your voice matters!"
else:
    show "You can't vote yet"
    show "But you can still learn about politics!"

What this does:

  1. Checks a condition (is age >= 18?)
  2. If true: runs the indented code after when
  3. If false: runs the indented code after else

🔍 Comparison Operators - Making Comparisons

Basic Comparisons

# Equal to
when name == "Alex":
    show "Hello, Alex!"

# Not equal to
when weather != "sunny":
    show "Take an umbrella!"

# Greater than
when score > 100:
    show "Excellent score!"

# Less than
when temperature < 32:
    show "It's freezing!"

# Greater than or equal to
when age >= 16:
    show "You can drive!"

# Less than or equal to
when price <= 50:
    show "This is affordable!"

🧠 For Neurodivergent Learners

Remember the pattern: when [something] [comparison] [something else]:

  • The colon : is always needed
  • The indented code only runs if the comparison is true
  • Use else: for what happens if it's false

🎯 Real-World Examples

Example 1: Grade Checker

think "Checking student grades"
grade = 85

when grade >= 90:
    show "Grade: A - Excellent work!"
when grade >= 80:
    show "Grade: B - Good job!"
when grade >= 70:
    show "Grade: C - Passing grade"
when grade >= 60:
    show "Grade: D - Need improvement"
else:
    show "Grade: F - Please study more"

Example 2: Weather Advisor

think "Giving weather advice"
temperature = 75
is_raining = false

when temperature > 80:
    show "It's hot! Wear light clothes."
when temperature > 60:
    show "It's nice! Perfect for a walk."
else:
    show "It's cold! Wear a jacket."

when is_raining:
    show "Don't forget your umbrella!"
else:
    show "No rain expected!"

Example 3: Age-Appropriate Activities

think "Suggesting activities based on age"
age = 14

when age >= 18:
    show "You can: Vote, get a credit card, rent a car"
when age >= 16:
    show "You can: Drive, get a job, open a bank account"
when age >= 13:
    show "You can: Use most social media, babysit, volunteer"
else:
    show "You can: Play, learn, explore hobbies"

🔗 Multiple Conditions

And Logic (and)

Both conditions must be true:

age = 20
has_license = true

when age >= 18 and has_license:
    show "You can rent a car!"
else:
    show "You need to be 18+ with a license"

Or Logic (or)

At least one condition must be true:

day = "Saturday"
is_holiday = false

when day == "Saturday" or day == "Sunday" or is_holiday:
    show "It's a day off!"
else:
    show "It's a work day"

Complex Conditions

think "Checking movie theater admission"
age = 16
has_parent = false
movie_rating = "R"

when age >= 17:
    show "You can see any movie"
when age >= 13 and has_parent:
    show "You can see PG-13 movies with parent"
when movie_rating == "G":
    show "You can see G-rated movies"
else:
    show "You need to be older or have a parent"

🎨 Accessibility Features

🧠 For ADHD/Executive Function

Use thinking blocks to organize your logic:

think "Step 1: Check if user is old enough"
when age >= 18:
    think "Step 2: They're old enough, check other requirements"
    when has_id:
        think "Step 3: All requirements met"
        show "Access granted!"

👁️ For Visual Accessibility

Use clear indentation and spacing:

# Good: Clear structure
when condition1:
    show "First action"
    show "Second action"
else:
    show "Alternative action"

# Avoid: Confusing structure
when condition1: show "Action"
else: show "Alternative"

🎧 For Screen Reader Users

Use descriptive variable names:

# Good: Clear when spoken
when user_age >= legal_voting_age:
    show "User can vote"

# Avoid: Unclear when spoken
when a >= 18:
    show "OK"

🚀 Building a Decision-Making Program

Let's build a Personal Activity Recommender:

think "Personal Activity Recommender"
show "=== Activity Recommender ==="

# Input your information
age = 25
weather = "sunny"
has_money = true
energy_level = 7  # out of 10
is_weekend = true

# Age-based recommendations
think "Checking age-appropriate activities"
when age >= 21:
    show "Age-appropriate: All adult activities available"
when age >= 18:
    show "Age-appropriate: Most activities available"
when age >= 13:
    show "Age-appropriate: Teen activities available"
else:
    show "Age-appropriate: Kid-friendly activities"

# Weather-based recommendations
think "Checking weather conditions"
when weather == "sunny":
    show "Weather: Perfect for outdoor activities!"
    when has_money:
        show "Suggestion: Visit a theme park or beach"
    else:
        show "Suggestion: Go for a walk or hike"
when weather == "rainy":
    show "Weather: Better to stay indoors"
    show "Suggestion: Movie, reading, or gaming"
else:
    show "Weather: Check conditions and dress appropriately"

# Energy-based recommendations
think "Checking energy level"
when energy_level >= 8:
    show "Energy: You're feeling great!"
    show "Suggestion: Try something active or challenging"
when energy_level >= 5:
    show "Energy: You're doing okay"
    show "Suggestion: Moderate activities work well"
else:
    show "Energy: You might want to rest"
    show "Suggestion: Relaxing activities recommended"

# Day-based recommendations
think "Checking if it's weekend"
when is_weekend:
    show "Schedule: It's the weekend!"
    show "Suggestion: Time for fun activities"
else:
    show "Schedule: It's a weekday"
    show "Suggestion: Consider your work/school schedule"

show "=== Recommendations Complete ==="

🔧 Common Decision-Making Patterns

Pattern 1: Range Checking

# Check if a number is in a range
score = 85
when score >= 80 and score <= 89:
    show "B grade range"

Pattern 2: Multiple Options

# Handle multiple possibilities
day = "Monday"
when day == "Monday":
    show "Start of work week"
when day == "Friday":
    show "End of work week"
when day == "Saturday" or day == "Sunday":
    show "Weekend!"

Pattern 3: Nested Decisions

# Decisions within decisions
has_account = true
when has_account:
    is_premium = true
    when is_premium:
        show "Access to premium features"
    else:
        show "Basic account features"
else:
    show "Please create an account"

🆘 Common Mistakes and Solutions

Mistake 1: Forgetting the Colon

# Wrong
when age >= 18
    show "Adult"

# Right
when age >= 18:
    show "Adult"

Mistake 2: Wrong Indentation

# Wrong
when age >= 18:
show "Adult"

# Right
when age >= 18:
    show "Adult"

Mistake 3: Using = Instead of ==

# Wrong (assignment)
when age = 18:
    show "Exactly 18"

# Right (comparison)
when age == 18:
    show "Exactly 18"

🎯 Practice Exercises

Exercise 1: Simple Decision

think "Practice: Simple age check"
age = 16

# Add your decision logic here
when age >= 18:
    show "You can vote!"
else:
    show "You can't vote yet"

Exercise 2: Multiple Conditions

think "Practice: Weather and activity planner"
weather = "sunny"
temperature = 75
has_money = true

# Add your decision logic here
# Consider weather, temperature, and money

Exercise 3: Complex Logic

think "Practice: Game character stats"
health = 80
magic = 50
level = 15

# Add logic to determine what the character can do
# Consider different combinations of stats

🌟 What's Next?

Now that you understand decision making, you're ready to:

  1. Learn about Loops - Loops and Repetition
  2. Build Functions - Functions
  3. Create Your First Project - First Project

Remember:

  • Start simple - Basic when statements first
  • Use thinking blocks - Document your logic
  • Test different values - See how your decisions work
  • Practice regularly - Decision making is a core skill

🎉 Congratulations!

You now understand how to make your programs intelligent! Decision making is one of the most important skills in programming. Every smart application uses these concepts.

Keep practicing and experimenting! Try different conditions, combine them in new ways, and see what interesting behaviors you can create.


This guide is constantly updated based on feedback from learners of all ages. Have questions or suggestions? Let us know!