0Pricing
Coding for Kids · Lesson

Choosing an Operation

Pick with if.

Choosing an Operation is a free Coding for Kids lesson on CoddyKit — lesson 3 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Coding for Kids learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

Let the User Choose! 🎛️

Hi captain! 🧑‍✈️ A real calculator lets YOU pick what to do: add, subtract, multiply, or divide! 🎛️

To do that, we use the magic word if! Let's learn it!

print('What math should I do? ➕➖✖️➗')

Asking for a Choice ❓

First, we ask the user which operation they want. We save their answer in a box called choice. ❓

choice = input('Type + or - or * or /: ')
print('You chose', choice)

The if Word 🤔

The word if means "only do this WHEN something is true"! 🤔

We check: if the choice equals '+', then add. We use TWO equal signs == to compare!

choice = '+'
if choice == '+':
    print('I will add! ➕')

Two Equals Means Compare ⚖️

Careful! One = puts a value in a box. TWO == asks "are these the same?" ⚖️

For checking, always use ==!

color = 'red'
if color == 'red':
    print('Stop! 🛑')

Else If With elif 🔀

What if it's NOT plus? We use elif (short for "else if") to check the next choice! 🔀

choice = '-'
if choice == '+':
    print('Adding!')
elif choice == '-':
    print('Subtracting!')

Checking All Four 🎯

Let's check all four operations using if and elif! Each one waits for its turn. 🎯

choice = '*'
if choice == '+':
    print('Add')
elif choice == '-':
    print('Subtract')
elif choice == '*':
    print('Multiply')
elif choice == '/':
    print('Divide')

The else Catch-All 🪤

What if someone types something silly like 'banana'? 🍌 We use else to catch anything that didn't match! 🪤

choice = 'banana'
if choice == '+':
    print('Add')
else:
    print('I do not know that one! 🤷')

Choice Plus Numbers 🔢

Now let's put it together! Get two numbers AND a choice, then do the right math! 🔢

a = 6
b = 2
choice = '+'
if choice == '+':
    print(a + b)
elif choice == '-':
    print(a - b)

The Full Chooser 🎛️

Here's the whole choosing machine with all four operations! Change choice to test each one. 🎛️

a = 12
b = 4
choice = '*'
if choice == '+':
    print(a + b)
elif choice == '-':
    print(a - b)
elif choice == '*':
    print(a * b)
elif choice == '/':
    print(a / b)
else:
    print('Unknown! 🤷')

Ask the User for Real 🗣️

Now with real input! Ask the numbers and the choice, then calculate. This is a true calculator brain! 🧠

a = int(input('First number: '))
b = int(input('Second number: '))
op = input('Choose + - * /: ')
if op == '+':
    print(a + b)
elif op == '-':
    print(a - b)
elif op == '*':
    print(a * b)
elif op == '/':
    print(a / b)

You Control the Math! 🚀

Amazing! Now your program does DIFFERENT things depending on the choice. 🚀 This is called making decisions, and it's super powerful!

op = '/'
if op == '/':
    print('Dividing time! ➗')
else:
    print('Something else!')

Quick Check! 🧠

Test your decision-making smarts! 🤔

Choosing Champion! 🎉

Fantastic! 🎉 Your calculator can make choices!

  • if runs code only when something is true 🤔
  • == compares (two equals!) ⚖️
  • elif checks more conditions 🔀
  • else catches the rest 🪤

Next: showing the answer nicely! 📢

op = '+'
if op == '+':
    print('Ready to add! ➕')

Frequently asked questions

Is the “Choosing an Operation” lesson free?

Yes — the full text of “Choosing an Operation” is free to read here on the web, and the Coding for Kids course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Coding for Kids course, upgrade to CoddyKit PRO.

What will I learn in “Choosing an Operation”?

Pick with if. You practise Coding for Kids with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Coding for Kids?

No prior experience is required. Coding for Kids on CoddyKit is structured for beginners through advanced learners; this is — lesson 3 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Choosing an Operation” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Coding for Kids lesson?

Yes. Every Coding for Kids lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Getting Two Numbers
  2. Doing the Math
  3. Choosing an Operation
  4. Showing the Answer
← Back to Coding for Kids