Learning Python from scratch is a great choice—it’s beginner-friendly, versatile, and can open doors to
earning potential through freelancing, automation, or data analysis. I’ll guide you through the basics
step-by-step, assuming no prior programming experience. The goal is to make this clear, practical, and
engaging, with examples you can try right away. We’ll start with fundamentals and progress to simple
projects, ensuring you understand each concept before moving forward. If you want to focus on specific
areas (e.g., web development, data analysis, or automation), let me know, and I can tailor the lessons.
For now, I’ll provide a structured intro to get you coding confidently.
---
### **Python from Scratch: Lesson 1 - Getting Started**
#### **1. Why Python?**
- **Simple Syntax**: Reads like English, making it easy to learn.
- **Versatile**: Used for web apps, data science, automation, and more.
- **Job Opportunities**: Freelancers can earn $20-$50/hour on platforms like Upwork for basic Python
tasks (e.g., scripting or data processing).
- **Free Tools**: Python is free, and you can start coding with minimal setup.
#### **2. Setting Up Python**
To start coding, you need Python installed and a place to write code.
- **Install Python**:
1. Download Python (version 3.12 or later recommended) from
[python.org](https://www.python.org/downloads/).
2. Follow the installer instructions for your system (Windows, macOS, or Linux). Check “Add Python to
PATH” during installation.
3. Verify installation: Open a terminal (Command Prompt on Windows, Terminal on macOS/Linux) and
type `python --version`. You should see the version number (e.g., Python 3.12.4).
- **Choose an Editor**:
- **Beginner-Friendly**: Use IDLE (comes with Python) or an online editor like
[Replit](https://replit.com/) (no installation needed).
- **Recommended**: Install Visual Studio Code (free) with the Python extension for a better
experience.
- **Alternative**: Use Jupyter Notebook (install via `pip install jupyter`) for interactive coding, great for
data tasks.
- **Test Your Setup**: Open your editor, create a file named `hello.py`, write `print("Hello, World!")`,
save, and run it. If you see “Hello, World!” in the output, you’re set.
#### **3. Python Basics: Your First Steps**
Python is all about writing instructions (code) that a computer executes. Let’s cover the essentials.
##### **A. Variables and Data Types**
Variables store data, like numbers or text. Think of them as labeled boxes.
- **Numbers** (Integers and Floats):
```python
age = 25 # Integer (whole number)
height = 1.75 # Float (decimal number)
print(age) # Output: 25
print(height) # Output: 1.75
```
- **Strings** (Text):
```python
name = "Tinashe" # Text in quotes
greeting = 'Hello, ' + name + '!' # Concatenation
print(greeting) # Output: Hello, Tinashe!
```
- **Booleans** (True/False):
```python
is_student = True
print(is_student) # Output: True
```
- **Try It**: Create a variable `city = "Harare"` and print it.
##### **B. Basic Operations**
- **Math**: Use `+`, `-`, `*`, `/` for addition, subtraction, multiplication, and division.
```python
price = 100
tax = price * 0.15
total = price + tax
print(total) # Output: 115.0
```
- **String Operations**:
```python
message = "Python " * 3
print(message) # Output: Python Python Python
```
- **Try It**: Calculate the total cost of 5 items priced at $20 each with a 10% discount.
##### **C. User Input**
Get input from users to make programs interactive.
```python
name = input("Enter your name: ")
print("Hello, " + name + "!")
```
- **Note**: `input()` returns a string. Convert to numbers if needed:
```python
age = int(input("Enter your age: ")) # Convert string to integer
print(age + 5) # Output: Your age + 5
```
- **Try It**: Ask for a user’s favorite number and print it doubled.
##### **D. Conditionals (If-Else)**
Make decisions based on conditions.
```python
age = int(input("Enter your age: "))
if age >= 18:
print("You can vote!")
else:
print("You're too young to vote.")
```
- **Operators**: Use `==` (equals), `!=` (not equals), `<`, `>`, `<=`, `>=` for comparisons.
- **Try It**: Write a program that checks if a number is positive or negative.
##### **E. Lists**
Store multiple items in a single variable.
```python
fruits = ["mango", "banana", "orange"]
print(fruits[0]) # Output: mango (first item, index 0)
fruits.append("apple") # Add to list
print(fruits) # Output: ['mango', 'banana', 'orange', 'apple']
```
- **Try It**: Create a list of 3 cities, add a fourth, and print the list.
#### **4. Your First Mini-Project: Simple Calculator**
Combine what you’ve learned to build a basic calculator.
```python
print("Simple Calculator")
num1 = float(input("Enter first number: "))
num2 = float(input("Enter second number: "))
operation = input("Choose operation (+, -, *, /): ")
if operation == "+":
result = num1 + num2
elif operation == "-":
result = num1 - num2
elif operation == "*":
result = num1 * num2
elif operation == "/":
if num2 != 0:
result = num1 / num2
else:
result = "Error: Cannot divide by zero!"
else:
result = "Invalid operation"
print("Result:", result)
```
- **Run It**: Save this as `calculator.py`, run it, and test different inputs.
- **Challenge**: Add a modulo (`%`) operation to calculate remainders.
#### **5. Practice Exercises**
To solidify your skills, try these:
1. Write a program that asks for a user’s name and age, then prints a message like “Tinashe, in 5 years
you’ll be 30!”
2. Create a list of 5 items you’d buy, then print the third item and the list’s length.
3. Write a program that checks if a number is even or odd (hint: use modulo `%`).
#### **6. Next Steps**
- **What’s Next**: In the next lesson, we’ll cover loops (repeating tasks), functions (reusable code), and
basic error handling. This will let you build more complex programs, like a to-do list or budget tracker.
- **Resources**:
- Free: [Python.org Tutorials](https://docs.python.org/3/tutorial/)
- Interactive: [codecademy.com](https://www.codecademy.com/learn/learn-python-3) (free basic
course)
- Practice: [w3schools.com/python](https://www.w3schools.com/python/)
- **Tip**: Code daily for 30-60 minutes. Start with small scripts, and experiment in your editor or Replit.
#### **7. Questions for You**
- Do you have Python installed, or are you using an online editor? Let me know so I can tailor examples.
- Want to focus on a specific goal (e.g., automation, data analysis, or a project relevant to Zimbabwe)?
- Any part of this lesson unclear, or want more practice problems?
Try the exercises and share your code or questions. I’ll provide feedback and guide you to the next level!