Input and Decisions
Ask questions, and choose what to do.
Customers keep asking Ava the same question. Is my order eligible for free delivery? She wants a program that asks for the order total, and answers on its own. For that, the program needs two new skills. Asking the user for information, and making a decision.

- Skill one: ask the user for input
- Skill two: make decisions with if
- Goal: a free delivery checker
Asking with input()
The input function pauses the program, shows a message, and waits for the user to type. Whatever they type comes back as a string, always. Even if they type a number, it is still text. To do maths, convert it, with int for whole numbers, or float for decimals.
name = input("Your name: ")
print(f"Hello, {name}!")
qty = int(input("How many plants? "))
print("Ordered:", qty)
print("Next order:", qty + 1)Your name: Maya Hello, Maya! How many plants? 3 Ordered: 3 Next order: 4
Comparison operators
To decide, Python compares values. Double equals checks if two values are equal. Remember, a single equals stores a value, and a double equals asks a question. Exclamation equals means not equal. Then greater than, less than, and their or equal versions. Every comparison gives back a boolean, True or False.
| Operator | Meaning | Example | Result |
|---|---|---|---|
| == | equal to | 5 == 5 | True |
| != | not equal | 5 != 3 | True |
| > | greater than | 3 > 5 | False |
| < | less than | 3 < 5 | True |
| >= | at least | 5 >= 5 | True |
| <= | at most | 4 <= 3 | False |
if, elif and else
Now the decision. The if keyword checks a condition, and ends with a colon. The indented lines below run only when the condition is true. Use elif for more conditions, and else for everything left over. The indentation, four spaces, is how Python knows which lines belong together. It is not decoration, it is the syntax.
total = 65
if total >= 100:
print("Free delivery + gift!")
elif total >= 50:
print("Free delivery!")
else:
print("Delivery costs $5")Free delivery!
and, or, not
Combine conditions with and, or, and not. And needs both sides to be true. Or needs at least one. Not flips true to false. Here, Ava gives a student discount only to students who also order at least two plants. Notice how the code reads almost like English.
is_student = True
plants = 3
if is_student and plants >= 2:
print("Student discount applied")
if plants > 10 or is_student:
print("You get a free pot")
if not is_student:
print("Join our student club")Student discount applied You get a free pot
Truthy and falsy
Python can treat any value as true or false. Zero, an empty string, an empty list, and None count as false. Almost everything else counts as true. So you can write, if name, to check that the text is not empty. It is a small trick, loved by Python programmers.
The free delivery checker
Time to build Ava's checker. We ask for the total, convert it, and decide. Orders of fifty or more ship free, and others pay five dollars. Run it with a small order, and it tells the customer exactly how much more to spend. That is a real, useful program, in just a few lines.
total = float(input("Order total: $"))
if total >= 50:
print("Free delivery!")
else:
need = 50 - total
print(f"Add ${need:.2f} more for free delivery")Order total: $32.5 Add $17.50 more for free delivery
Plant care advisor
Your turn. Ask the user how many days since they watered their plant. If it is seven days or more, print, Time to water. Otherwise, print, It is fine for now. Ready? Here is one solution. Convert the input to an int, compare, and print. Try it with different numbers.
Ask for days since watering. 7 or more: "Time to water". Otherwise: "It is fine for now".
Show hint
int(input(...)) then if / else
Show solution
days = int(input("Days since watering: "))
if days >= 7:
print("Time to water")
else:
print("It is fine for now")Days since watering: 9 Time to water
Summary
Brilliant. Your programs can now ask questions and make decisions. You know that input always returns text, how to convert it, how comparisons work, and how if, elif and else choose a path. Next, Ava wants the computer to repeat work for her, with loops.
Key takeaways- input() returns text: convert with int/float
- Compare with == != > < >= <=
- if / elif / else, with indentation