Skip to content

Python Basics II: Text-Based Programming

Course overview

This course teaches the core concepts of text-based Python programming. Without turtle graphics, students work purely with data, interact with the user, and write logical programs. The concepts learned at this stage form the foundation of every area of programming.

Estimated time: 36-64 hours

The time required depends on the student's grade level, prior experience, and learning speed, and varies greatly. It also differs between just learning the basic concepts and moving on, versus additional practice problems or creative projects: taking those on makes a difference too. The times above are an average range, so please proceed flexibly at your child's pace.

What abilities will it build?

Distinguishing kinds of data (numbers, text, true/false) and making decisions based on data - "Data-Driven Decision Making" - is the skill students train. In modern society, every field - medical diagnosis, financial analysis, business strategy - runs on data-based decisions. In this course, students learn the foundations of that mindset.

What principles will you learn?

  • (data types) Numbers, strings, booleans, and so on - distinguishing kinds of data is the first step in data processing. Just as Excel treats numbers and text differently, a computer's handling depends on the data type.
  • (condition-based decisions) Rules like "if the score is 90 or above, grade A" are data-based rules expressed in code. This is the basic principle by which AI makes decisions and the heart of every automation system.
AI-era thinking: computing (problem-solving) | data-driven | probabilistic thinking

Computational Thinking

Skill Description Example activity
⚖️ Logical comparison Judging the relationship between two values score >= 60 -> determine pass/fail
🔀 Conditional branching Different handling depending on the case use if-elif-else to classify grades A/B/C/D/F
🛡️ Exception handling Anticipating and preparing for error situations use try-except to handle bad input
↔️ Type conversion Converting between data formats int("123") -> text to number

Mathematical connections

Math concept Programming application Learning benefit
Inequalities x > 5 and x < 10 Expressing ranges, solutions of inequalities
Modulo operation n % 2 == 0 -> determine even numbers Multiples, divisors, the concept of periodicity
Logical operations and, or, not Propositional logic, intersection/union of sets
Exponentiation 2 ** 10 → 1024 Laws of exponents, exponential growth

Training logical thinking

Logical structure Description Real-life example
AND True only if all conditions are true "If you did your homework AND cleaned, you get allowance"
OR True if at least one is true "If it rains OR snows, stay home"
NOT Flips true <-> false "NOT late -> not tardy"

The debugging thought process

flowchart LR
    A[Error occurs] --> B[Read the error message]
    B --> C[Guess the cause]
    C --> D[Test the hypothesis]
    D --> E[Fix]
    E --> F[Verify]
    F -.->|error again| C
💻 Code examples & visualization

Example 1: Differences Between Data Types

# Number vs string
num = 5
text = "5"

print(num + 10)     # 15 (numeric addition)
print(text + "10")  # "510" (string concatenation)
print(int(text) + 10)  # 15 (addition after type conversion)

Data type comparison:

┌────────────┬────────────┬────────────┐
│   Type     │   Example  │    Result   │
├────────────┼────────────┼────────────┤
│ int (integer)│  5       │  5 + 10 = 15│
│ str (string)│   "5"     │ "5"+"10"="510"│
│ float(decimal)│ 5.0      │ 5.0+10 = 15.0│
│ bool(true/false)│ True   │ True+1 = 2  │
└────────────┴────────────┴────────────┘


Example 2: Conditionals - Grade Calculator

score = int(input("Enter your score: "))

if score >= 90:
    grade = "A"
elif score >= 80:
    grade = "B"
elif score >= 70:
    grade = "C"
elif score >= 60:
    grade = "D"
else:
    grade = "F"

print(f"Your grade is {grade}It is.")

Flowchart:

flowchart TD
    A[Enter score] --> B{score ≥ 90?}
    B -->|Yes| C[Grade A]
    B -->|No| D{score ≥ 80?}
    D -->|Yes| E[Grade B]
    D -->|No| F{score ≥ 70?}
    F -->|Yes| G[Grade C]
    F -->|No| H{score ≥ 60?}
    H -->|Yes| I[Grade D]
    H -->|No| J[Grade F]


Example 3: Logical Operators

age = 15
has_id = True

# AND: true only if both are true
if age >= 18 and has_id:
    print("Can enter")
else:
    print("No entry")

# OR: true if even one is true
is_weekend = True
is_holiday = False

if is_weekend or is_holiday:
    print("Day off!")

Logical operation truth table:

┌─────┬─────┬─────────┬────────┐
│  A  │  B  │ A and B │ A or B │
├─────┼─────┼─────────┼────────┤
│  T  │  T  │    T    │   T    │
│  T  │  F  │    F    │   T    │
│  F  │  T  │    F    │   T    │
│  F  │  F  │    F    │   F    │
└─────┴─────┴─────────┴────────┘


Example 4: while Loop - Number Guessing Game

import random

answer = random.randint(1, 100)
guess = 0
tries = 0

while guess != answer:
    guess = int(input("Guess the number (1-100): "))
    tries += 1

    if guess < answer:
        print("Higher! ⬆️")
    elif guess > answer:
        print("Lower! ⬇️")

print(f"Correct! {tries} tries! 🎉")

Flowchart:

flowchart TD
    A[Generate answer<br/>1~100 random] --> B[Enter number]
    B --> C{Correct?}
    C -->|Yes| D[🎉 Success!]
    C -->|No| E{guess < answer?}
    E -->|Yes| F[Higher ⬆️]
    E -->|No| G[Lower ⬇️]
    F --> B
    G --> B


Example 5: Exception Handling - Safe Input

while True:
    try:
        age = int(input("Enter your age: "))
        break  # End the loop on success
    except ValueError:
        print("❌ Please enter a number!")

print(f"Age entered: {age}")

Example run:

Enter your age: abc
❌ Please enter a number!
Enter your age: fifteen
❌ Please enter a number!
Enter your age: 15
Age entered: 15


1. Mastering Output (print)

Item Content
What will you learn? How to print text to the screen
Core Concepts Input/output, function calls, strings

print() The function is the first way to talk with a computer. Students can see what happens as the code runs. It is the most basic tool for debugging (finding errors), and even professional programmers use it every day. They learn that you must give commands to the computer in the exact format, which is the start of understanding why syntax matters.


2. Values and Data Types (int, float, str, bool)

Item Content
What will you learn? Kinds of data: numbers, strings, booleans, and more
Core Concepts Data representation, the type system

A computer stores all information as 0s and 1s, but a programming language presents it in a form people can easily understand. Numbers (integers, decimals), strings (text), and booleans (true/false) are the most basic data types. Students learn that "5" and 5 are different - one is text and one is a number. Understanding data types gives a fundamental understanding of how a computer processes information.


3. The Calculation Engine: Arithmetic Operators

Item Content
What will you learn? Addition, subtraction, multiplication, division, and special operations
Core Concepts Calculation, expressions, operator precedence

In programming, operators are tools for manipulating data. Besides the basic math operations (+, -, , /), students also learn special operations like modulo (%) and exponentiation (*). The modulo operation is often used for practical problem-solving such as determining even/odd or calculating time. Understanding operator precedence lets you write complex expressions accurately.


4. Criteria for Decisions: Comparison Operators

Item Content
What will you learn? Comparing values to decide true/false
Core Concepts Logical decisions, boolean results

Comparison operators (==, !=, <, >, <=, >=) compare two values and return True or False. This is the basis for a computer making a "decision." You can express questions like "Is the score 60 or above?" or "Is the age under 18?" in code. Students build the ability to define conditions clearly of reading and interpreting error messages.


5. The Logic of Conditions: and / or / not

Item Content
What will you learn? Combining conditions with and, or, not
Core Concepts Compound conditions, boolean algebra

Logical operators combine multiple conditions to make more complex decisions possible. and means "and" (true only if both are true), or means "or" (true if even one is true), and not means "not." You can express complex real-world rules in code, such as "students with a score of 60 or above and attendance of 80% or more." This concept connects to set theory and logic in mathematics.


6. The Rhythm of Repetition: the while Loop

Item Content
What will you learn? Repeating while a condition is true
Core Concepts Repetition, loops, condition-based repetition

whileThe statement "keep going while ~" is the command. It repeats a block of code while the condition is true. For example, it fits situations like "keep asking until the user enters 'quit'." Students learn that setting the loop condition wrong can land them in an infinite loop, and they realize how important condition design is.


7. Flow Control: break & continue

Item Content
What will you learn? Exiting a loop in the middle
Core Concepts Loop control, handling special situations

breakthe loop forcibly stops it, and continueis skips the current iteration and moves on. For example, once you find the item you want in a list, there's no need to search the rest. This is the start of efficient programming, and students learn how to cut out unnecessary work.


8. Working with Text: Strings

Item Content
What will you learn? Working with text data
Core Concepts String manipulation, indexing, slicing

A string Text data is how text is represented. Students learn to join strings, cut them, and find specific characters. Indexing (accessing by character position) and slicing (extracting a part) are techniques for handling data in fine detail. This concept is used very often in real programs, such as processing user names and analyzing messages.


9. Talking via Input: input()

Item Content
What will you learn? Getting data from the user
Core Concepts User interaction, data type conversion

input() A function makes a program interactive . The program can receive and process data the user types on the keyboard. The key point is that input() always returns a string, so to use it as a number you need Type conversion conversion. With this concept, students can build interactive programs such as quiz games and calculators.


10. Safeguards and Recovery: Exception Handling (try-except)

Item Content
What will you learn? Keeping a program from stopping when an error occurs
Core Concepts Exception handling, stability, defensive programming

A program can raise an error in unexpected situations (the user enters text instead of a number, a file is missing, etc.) raise an error. try-except Using the syntax, even when an error occurs the program can handle it gracefully and keep running. Students develop a defensive mindset of reading and interpreting error messages.


When you finish this course...

Learning outcomes

Students will be able to:

  • Understand and convert various data types
  • Write interactive programs that take user input and process it
  • Implement complex repetition logic withand while loops and flow control
  • Exception handlingWrite stable programs with it
  • text-based algorithm problem-solving skills
  • Be ready to expand into many fields such as data processing and game development solid foundation for moving on to more complex projects