← BackGrades 7-8 | Chapter 1: Python Basics

Introduction to Python 🐍

Start Coding Today

Session 1: Python Fundamentals

What Is Python? 🤔

Python is a programming language - a way to tell computers exactly what to do, step by step.

Why Python?

  • Easy to read: Python code looks almost like English
  • Powerful: Used in AI, data science, web development, games
  • Beginner-friendly: Perfect for learning programming
  • In-demand skill: Companies hire Python programmers everywhere

Fun fact: Python is named after Monty Python, not the snake!

Your First Program: Print 📤

The simplest Python program uses print() - this tells Python to display text on the screen.

Code Example:

print("Hello, World!")

Output: Hello, World!

Notice: Text inside quotes is called a string - it's just text data.

Variables: Storing Information 💾

A variable is a container that holds information. You can store numbers, text, and more.

Code Example:

name = "Alice"
age = 13
print(name)
print(age)

Output:
Alice
13

Input: Getting Information from Users 🎤

The input() function lets you ask users to type information.

Code Example:

name = input("What's your name? ")
print("Hello, " + name + "!")

Interaction:
Computer asks: What's your name?
You type: Bob
Computer says: Hello, Bob!

Math Operations 🔢

Python can do math! Use +, -, *, / for add, subtract, multiply, divide.

Code Examples:

x = 10
y = 5
print(x + y) # Shows 15
print(x - y) # Shows 5
print(x * y) # Shows 50
print(x / y) # Shows 2.0

Project 1: Age Calculator 🎂

Let's create a program that calculates how old you'll be in 10 years!

Code:

age = input("How old are you? ")
age = int(age) # Convert text to number
future_age = age + 10
print("In 10 years, you'll be " + str(future_age))

New concepts: int() converts text to numbers, str() converts numbers to text

Project 2: Simple Math Quiz 🧮

Code:

answer = input("What is 7 + 3? ")
answer = int(answer)
if answer == 10:
  print("Correct!")
else:
  print("Wrong! The answer is 10")

This introduces if/else! More on that next session.

Try It Yourself! 💪

Online Python Editors (No Installation!):

  • Replit.com: Create free account, start coding instantly
  • Trinket.io: Simple and beginner-friendly
  • Python.org: Official Python editor online

Your Challenge:

Write a program that:

  • Asks for your name
  • Asks for your favorite number
  • Multiplies that number by 2
  • Prints "Hi [name], your number times 2 is [result]!"

What We Learned 🎓

  • Python is a beginner-friendly programming language
  • print() displays text on screen
  • Variables store information
  • input() gets information from users
  • Math operations (+, -, *, /) do calculations
  • int() and str() convert between numbers and text
  • You can write REAL programs right now!

You Can Code! 🎉

You've written your first Python programs

Next Session: Make Programs Smarter with If/Else Logic