Zum Inhalt springen

English:Introduction to Python

Aus MOOCsWiki Staging
Version vom 13. August 2026, 10:56 Uhr von Glanz (Diskussion | Beiträge) (aiMOOC über GPT aiMOOC Action erstellt)
(Unterschied) ← Nächstältere Version | Aktuelle Version (Unterschied) | Nächstjüngere Version → (Unterschied)

Introduction to Python



Introduction

Welcome to Introduction to Python. In this aiMOOC, you will learn how to give a computer clear instructions using the Python programming language. The course is designed for Grades 7–8, so it begins with simple ideas and builds toward small programs that you can create, test, improve, and explain.

Python is a general-purpose programming language. It is widely used for learning programming as well as for areas such as data analysis, web development, automation, science, and artificial intelligence. Python code is often considered readable because many commands use short English-like words and because indentation is part of the program structure.

A program is a set of instructions that a computer follows. Programming is not only about typing code. You also learn to break a problem into steps, notice patterns, test ideas, find mistakes, and improve your solution. These are useful skills in computer science, mathematics, science, technology, and many other subjects.

By the end of this course, you should be able to:

  1. Explain what a program does: Describe how source code gives instructions to a computer.
  2. Write simple Python code: Use correct spelling, symbols, line breaks, and indentation.
  3. Store information in variables: Work with text, whole numbers, decimal numbers, and Boolean values.
  4. Use input and output: Ask the user for information and show useful results.
  5. Make decisions: Use if, elif, and else to choose between actions.
  6. Repeat actions: Use for loops and simple while loops.
  7. Organize several values: Create and use Python lists.
  8. Build functions: Group reusable instructions into named functions.
  9. Debug programs: Read error messages, test code, and correct mistakes.
  10. Create a visual program: Use turtle graphics to connect code with shapes and patterns.


What Is Python?

Python is both a programming language and the name of software that can run Python code. A Python program is usually saved as a text file with the ending .py. When you run the file, the Python interpreter reads the instructions and carries them out.

Python was created by Guido van Rossum and first released in the early 1990s. The name refers to the comedy group Monty Python, not to the snake. Today, Python is developed as an open-source project with a large worldwide community.

The official Python tutorial describes expressions, data types, control flow, functions, modules, and other language features. For this school-level course, you will focus on the parts that help you build clear beginner programs.

Official Python Tutorial


How You Can Run Python

You need a place where you can type and run code. One common beginner tool is IDLE, Python's Integrated Development and Learning Environment. It includes an interactive shell and a code editor. Your school may also use another editor or a browser-based coding environment.

Two useful ways to work are:

  1. Interactive shell: Type one instruction and see the result immediately. This is useful for quick experiments.
  2. Script file: Write several lines, save them in a .py file, and run the whole program. This is better for projects.

Your first program can be only one line:

print("Hello, world!")

The function print() displays information. Text inside quotation marks is a string.

Try it: Change the message so that the program greets your class, your school club, or a fictional character.


Core Python Skills


Values, Variables, and Data Types

A value is a piece of information, such as 12, 3.5, "Python", or True. A variable is a name that refers to a value.

name = "Maya"
age = 13
height = 1.58
likes_coding = True

In this example:

  1. String: "Maya" is text.
  2. Integer: 13 is a whole number.
  3. Float: 1.58 is a decimal number.
  4. Boolean: True represents one of two logical values, True or False.

Variable names can contain letters, numbers, and underscores, but they cannot begin with a number. Choose meaningful names such as score instead of unclear names such as x1 when the meaning matters.

score = 7
score = score + 1
print(score)

The program first stores 7 in score. Then it replaces that value with 8.

Think like a programmer: A variable is not a box permanently labeled with one value. Its value can change while a program runs.


Numbers and Operators

Python can act like a calculator.

print(8 + 3)
print(8 - 3)
print(8 * 3)
print(8 / 3)
print(8 // 3)
print(8 % 3)
print(2 ** 4)

Common arithmetic operators include:

  1. Addition: +
  2. Subtraction: -
  3. Multiplication: *
  4. Division: /
  5. Floor division: //
  6. Remainder: %
  7. Powers: **

Parentheses can make the intended order clear.

total = (4 + 6) * 3
print(total)

Mini challenge: Write a program that calculates the total price of three identical cinema tickets.


Input and Output

Programs become more interesting when they react to a user. The input() function displays a prompt and waits for the user to type text.

name = input("What is your name? ")
print("Hello,", name)

The result from input() is a string. If you want to calculate with a number entered by the user, convert it first.

age = int(input("How old are you? "))
next_age = age + 1
print("Next year you will be", next_age)

Useful conversions include int() for whole numbers, float() for decimal numbers, and str() for text.

Safety note: In school projects, do not ask users to enter private information such as passwords, home addresses, or other sensitive personal data.


Comparisons and Boolean Values

A comparison asks a question that has the answer True or False.

score = 8

print(score > 5)
print(score == 8)
print(score != 10)

Important comparison operators include == for "is equal to", != for "is not equal to", <, >, <=, and >=.

Be careful with = and ==. A single = assigns a value to a variable. A double == compares two values.


Decisions with if, elif, and else

A program can use a condition to decide which instructions to run.

temperature = 17

if temperature >= 20:
    print("A T-shirt may be enough.")
else:
    print("Take a jacket.")

The colon after the condition and the indentation on the next line are important. In Python, indentation shows which statements belong inside a block.

You can use elif when there are more than two choices.

score = 74

if score >= 90:
    print("Level: Expert")
elif score >= 70:
    print("Level: Skilled")
else:
    print("Level: Developing")

The program checks the conditions from top to bottom and runs the first matching branch.

Design challenge: Create a decision tree for choosing an activity based on weather conditions, then translate it into Python.


Repetition with for Loops

A loop repeats instructions. A for loop is useful when you know which items or how many steps you want to repeat.

for number in range(5):
    print(number)

This prints the values from 0 through 4. The ending value in range(5) is not included.

You can also repeat an action for every item in a list.

animals = ["fox", "owl", "seal"]

for animal in animals:
    print("I chose the", animal)

A while loop repeats as long as a condition stays true.

count = 3

while count > 0:
    print(count)
    count = count - 1

print("Go!")

When you write a while loop, make sure something can eventually make its condition false. Otherwise you may create an infinite loop.


Lists

A list stores several values in one ordered collection.

planets = ["Mercury", "Venus", "Earth", "Mars"]
print(planets[0])
print(len(planets))

Python uses zero-based indexing, so the first list item has index 0. The function len() tells you how many items are in a list.

You can add an item with append().

planets.append("Jupiter")
print(planets)

Mini challenge: Create a list of five school subjects. Use a loop to print one sentence about each subject.


Functions

A function is a named block of reusable code. You create your own function with def.

def greet(name):
    print("Welcome,", name)

greet("Sam")
greet("Amina")

The variable name inside the function definition is a parameter. The value you provide when calling the function is an argument.

Functions can also return values.

def double(number):
    return number * 2

answer = double(6)
print(answer)

Functions help you avoid repeating the same instructions and make larger programs easier to understand.


Thinking Like a Programmer


Algorithms and Flowcharts

An algorithm is a step-by-step method for solving a problem. You can plan an algorithm in ordinary language, as pseudocode, or with a flowchart before writing Python.

Example problem: Decide whether a student can borrow a sports item.

  1. Input: Ask whether the student has a school card.
  2. Decision: Check whether the answer is yes.
  3. Output: Display either "Item can be borrowed" or "Please show your school card."

A good algorithm is clear, has a sensible order, and eventually finishes.


Debugging and Error Messages

Most programmers make mistakes while coding. Debugging means finding and fixing problems.

Common beginner problems include:

  1. Syntax error: The code does not follow Python's grammar, perhaps because a colon or quotation mark is missing.
  2. Name error: The program uses a variable name that has not been defined or has been misspelled.
  3. Type error: An operation is attempted with incompatible kinds of values.
  4. Logic error: The program runs, but the result is not what you intended.

A useful debugging routine is:

  1. Read the error message and note the line number.
  2. Check spelling, punctuation, brackets, quotation marks, and indentation near that line.
  3. Print important variable values to see what the program is doing.
  4. Test one small part at a time.
  5. Change one thing, run the program again, and compare the result.

Example:

age = input("Age: ")
print(age + 1)

This causes a type problem because input() returns a string. A corrected version is:

age = int(input("Age: "))
print(age + 1)

Debugging is not a sign that programming has failed. It is part of the normal process of improving a program.


Comments and Readable Code

A comment begins with #. Python ignores the rest of that comment line.

# Convert minutes to seconds
minutes = 5
seconds = minutes * 60
print(seconds)

Good comments explain the purpose of a section or an idea that may be hard to understand. They should not simply repeat every obvious line.

Readable code also uses sensible variable names, consistent indentation, and small sections that each have a clear purpose.


Creative Coding with Turtle

Python's turtle module lets you control a small on-screen drawing cursor. It is a useful way to see how sequence, loops, angles, and functions work together.

A square can be drawn by repeating "move forward" and "turn right".

import turtle

pen = turtle.Turtle()

for side in range(4):
    pen.forward(100)
    pen.right(90)

turtle.done()

Once the square works, you can experiment with different numbers of sides, turning angles, colors, or repeated shapes.

Pattern idea:

import turtle

pen = turtle.Turtle()
pen.speed(0)

for step in range(36):
    for side in range(4):
        pen.forward(80)
        pen.right(90)
    pen.right(10)

turtle.done()

Before changing the code, predict what the drawing will look like. Then test your prediction and explain what happened.

Official Python turtle documentation


Mini Project: Build a Quiz Game

This project combines variables, input, decisions, and a score.

score = 0

answer = input("Which keyword starts a decision in Python? ")

if answer.lower() == "if":
    print("Correct!")
    score = score + 1
else:
    print("The answer is if.")

answer = input("Which function displays text? ")

if answer.lower() == "print":
    print("Correct!")
    score = score + 1
else:
    print("The answer is print.")

print("Your score is", score)

Improve the project by adding more questions, storing questions in a list, or writing a function that checks an answer. Make sure your questions are fair and your feedback is helpful.


Responsible and Safe Coding

Programming gives you the power to create useful tools, games, art, and experiments. Use that power responsibly.

  1. Protect privacy: Do not collect unnecessary personal information in beginner projects.
  2. Respect creators: Use media and code according to their licenses and give credit when required.
  3. Do not harm systems: Do not use school coding activities to bypass rules, access accounts, or interfere with devices or networks.
  4. Design for different users: Choose readable text, clear instructions, and sensible input options.
  5. Test fairly: Try different inputs, including unexpected ones, and improve the program when you find problems.


Interactive Tasks


Quiz: Test Your Knowledge

Which Python function displays text on the screen? (print) (!input) (!range) (!append)




Which kind of value is used for text in Python? (string) (!integer) (!float) (!boolean)




What does the statement score = 5 do? (It stores the value five under the name score) (!It repeats the program five times) (!It deletes the variable named score) (!It asks the user for a score)




What type of value does input return before conversion? (string) (!integer) (!float) (!boolean)




Which keyword begins a basic decision in Python? (if) (!for) (!def) (!import)




Why is indentation important in Python? (It shows which statements belong to a block) (!It changes every number into text) (!It adds comments automatically) (!It saves the program as a file)




What does a for loop help a program do? (Repeat instructions) (!Rename Python) (!Close every file) (!Remove all variables)




Which Python structure stores several ordered values? (list) (!comment) (!operator) (!condition)




Which keyword is used to define a function? (def) (!returning) (!repeat) (!function)




What is debugging? (Finding and fixing problems in a program) (!Deleting every line of code) (!Turning all variables into strings) (!Running code without testing it)





Memory Game

Variable A name that refers to a stored value
String A value that represents text
Boolean A logical value that is either True or False
Loop A structure that repeats instructions
List An ordered collection of values
Function A named reusable block of code
Debugging The process of finding and fixing program problems





Drag and Drop

Match the correct terms. Topic
Displays output print function
Gets text from a user input function
Chooses between actions conditional statement
Repeats a block loop
Stores several ordered values list




...


Crossword Puzzle

Variable What name can refer to a value that may change?
String What data type is used for text?
Boolean What data type can be True or False?
Function What reusable named block of code can perform a task?
Indentation What spacing shows code blocks in Python?
Debugging What process finds and fixes problems in code?





LearningApps


Cloze Text

Complete the text.

A Python program contains

that tell a computer what to do. A named place that refers to a value is called a

. Text data is commonly stored as a

. The input function first returns the user's answer as

. An if statement makes a

based on a condition. A for loop can

a block of instructions. A list stores several values in an

collection. A reusable named block of code is a

. Finding and fixing problems in a program is called

.




Open-Ended Tasks


Easy

  1. Personal Greeting Program: Write a Python program that asks for a first name or nickname and prints a friendly greeting. Test it with at least three different inputs.
  2. Python Calculator Card: Create a one-page illustrated guide showing the operators for addition, subtraction, multiplication, division, remainder, and powers, with one Python example for each.
  3. Variable Story: Write a short program that stores a character name, age, favorite activity, and one Boolean value, then prints a four-line description.
  4. Debugging Detective: Create a small Python program with three beginner mistakes, exchange it with a classmate, and write down how each mistake was found and fixed.


Standard

  1. Class Survey Program: Design a program that asks a safe, non-personal class survey question, stores several possible answers, and explains how the data could be counted without collecting sensitive information.
  2. Weather Decision Program: Build a program that uses input and if, elif, and else to suggest an activity for several weather conditions. Draw a flowchart before coding.
  3. Turtle Pattern Gallery: Produce at least three turtle drawings by changing loop counts, distances, and angles. Save screenshots and explain which code changes caused each visual change.
  4. Interview a Coder: Interview a teacher, student, family member, or local professional who uses programming. Ask how they learned, how they debug, and where Python or another language helps in their work.


Advanced

  1. Quiz Game Upgrade: Expand the course quiz game so that it has at least five questions, useful feedback, a score, and at least one function. Explain your testing method.
  2. Number Guessing Design: Plan and build a number-guessing game using a loop and decisions. Add a limit on attempts and give feedback that helps the player without revealing the answer immediately.
  3. School Helper Prototype: Identify a small school problem that could be helped by a simple program, create a paper or digital prototype, implement a Python version, and collect feedback from at least two test users.
  4. Python Explainer Video: Produce a two-to-four-minute video that teaches one concept from variables, conditionals, loops, lists, functions, or debugging. Include your own code example and a short challenge for viewers.



Learning Assessment

  1. Explain Program Flow: Given a short program that uses input, a decision, and output, explain the order in which the computer carries out the instructions and justify what will be displayed for two different inputs.
  2. Repair a Broken Program: Diagnose a program containing a syntax problem, a type problem, and a logic problem, then explain how each correction changes the program's behavior.
  3. Compare Loop Solutions: Solve one repetition problem with a for loop and another with a while loop, then explain why each loop type is suitable for its task.
  4. Design with Functions: Refactor a repeated section of code into a function with a parameter, test it with at least three arguments, and explain how the new design improves readability or reuse.
  5. Transfer to Mathematics: Write a Python program that calculates a mathematical quantity studied in class, verify the result by hand for one example, and discuss any assumptions in the program.
  6. Evaluate User Experience: Test a classmate's beginner program, give evidence-based feedback on prompts, error handling, readability, and usefulness, and propose two specific improvements.




Evidence of Learning

Strong evidence of learning can include both what you know and what you can create.

  1. Knowledge: You can explain variables, data types, input, output, conditions, loops, lists, functions, and debugging in your own words.
  2. Code reading: You can trace short Python programs and predict outputs for given inputs.
  3. Code writing: You can write and run small programs that combine several core Python ideas.
  4. Debugging skill: You can use error messages, tests, and print statements to locate and fix problems.
  5. Algorithmic thinking: You can plan a solution as steps or a flowchart before writing code.
  6. Project work: You can produce a working program, game, visual pattern, or school-use prototype and explain its design.
  7. Communication: You can explain your code clearly to another learner and use appropriate programming vocabulary.
  8. Transfer: You can apply Python to a new task in mathematics, science, art, technology, or another school subject.
  9. Responsible practice: You can make choices that protect privacy, respect creators, and avoid harmful uses of code.
  10. Reflection: You can describe what you changed after testing and why the improved version works better.




OERs on the Topic

The following openly accessible resources can help you review or extend your learning.

Official Python Tutorial

Official Python turtle documentation



Linked Learning Areas

Python connects naturally with several school learning areas. In Mathematics, you can calculate, test patterns, and explore coordinates. In Science, you can model measurements and organize data. In Art, turtle graphics can create geometric designs. In Technology education, you can build and test digital solutions. In English, you can practice precise instructions, explain procedures, and write clear user messages.


aiMOOC Projects