Day 3: Reviewing Yesterday’s Challenge + Virtual Environments & Repositories


 

Day 2 Challenge Review: How Did You Do?

Before we move forward, let’s recap the mini-challenge from Day 2:

Store your full name as a string and print it.
Create two numbers and add them together.
Store a boolean value and check its type.
Convert an integer to a string and print its type.
Create a list of 5 favorite foods and print the first one.

Common Mistakes & Fixes

πŸ”΄ Forgetting to use quotation marks for strings
✔️ Fix: full_name = "John Doe" instead of full_name = John Doe

πŸ”΄ Using + instead of , in print statements
✔️ Fix:

print("My name is", full_name)  # ✅ Works correctly  
print("My name is " + full_name)  # ✅ Also works

 

But this would fail:

print("My name is" + 25)  # ❌ TypeError: can only concatenate str (not "int") to str  
 
 

To fix this, convert the number to a string:

print("My name is " + str(25))  # ✅ Works correctly


πŸ”΄ Forgetting that lists are zero-indexed
✔️ Fix: If your list is foods = ["Pizza", "Burger", "Sushi", "Pasta", "Ice Cream"], the first item is accessed as foods[0], not foods[1].

Standout Submissions πŸŽ‰

Some of you went the extra mile by adding user input, loops, and functions—amazing! Keep pushing yourself! πŸ’ͺ

πŸ‘ Special shoutout to those who shared their results in the WhatsApp group! If you haven’t yet, go ahead and drop your screenshots! πŸ“Έ


Day 3: Virtual Environments & Repositories

Now that we’ve warmed up, let’s dive into today’s core topics:

Virtual Environments – Keeping projects organized and avoiding dependency conflicts.
Repositories (Git & GitHub) – Backing up your code, collaborating, and tracking changes like a pro.

By the end of this session, you'll set up a virtual environment and push your first Python project to GitHub! πŸ’ͺ


1️⃣ Why Use Virtual Environments?

Imagine working on two different Python projects, and one requires Django 3.2 while the other needs Django 4.0. Without virtual environments, your system might break because Python doesn’t know which version to use! 😬

A virtual environment:
πŸ”Ή Creates an isolated workspace for each project.
πŸ”Ή Prevents dependency conflicts between projects.
πŸ”Ή Keeps your global Python setup clean and organized.

Setting Up a Virtual Environment

Windows πŸ–₯️

1️⃣ Open Command Prompt (cmd).
2️⃣ Navigate to your project folder:

cd path\to\your\project 

3️⃣ Create a virtual environment:

python -m venv myenv
4️⃣ Activate it:
myenv\Scripts\activate
 

(You should see (myenv) appear in your terminal—this means it's active!)

Mac/Linux 🍏🐧

1️⃣ Open Terminal.
2️⃣ Navigate to your project folder:

$ cd /path/to/your/project

3️⃣ Create a virtual environment:

$ python3 -m venv myenv

4️⃣ Activate it:

$ source myenv/bin/activate

πŸ”Ή To deactivate a virtual environment (works for all OS):

deactivate

2️⃣ Introduction to Git & GitHub

You wrote some great Python code—now what? Time to back it up!

What is Git?

Git is a version control system that tracks changes in your code, so you can:
✅ Roll back to previous versions when things break.
✅ Collaborate with others without overwriting files.
✅ Work on different features without messing up the main code.

What is GitHub?

GitHub is an online platform where you can store and manage your Git repositories. Think of it as Google Drive for your code, but with superpowers. πŸ’ͺ


3️⃣ Setting Up Git & Pushing Your Code to GitHub

Before pushing code to GitHub, make sure you have:

✅ A GitHub accountSign up here

Git installed → Check by running:

$ git --version

If Git isn’t installed, download it here.

Step 1: Initialize Git in Your Project Folder

Navigate to your project folder and run:

$ git init

Step 2: Connect to GitHub

1️⃣ Create a new repository on GitHub.
2️⃣ Copy the repository URL.
3️⃣ Link your project to GitHub:

    $ git remote add origin your-repository-url

Step 3: Add, Commit & Push Your Code

1️⃣ Add all files to Git:

    $ git add .
2️⃣ Commit changes with a message:

    $ git commit -m "Initial commit"


3️⃣ Push your code to GitHub:

    $ git push -u origin main

πŸŽ‰ Congratulations! Your code is now safely stored in GitHub.


Mini-Challenge: Test Your Skills!

πŸ“ Try this:
1️⃣ Create a virtual environment in your project folder.
2️⃣ Activate it and install a package (e.g., requests).
3️⃣ Initialize a Git repository, commit your Python file, and push it to GitHub.
4️⃣ Share your GitHub repository link in the WhatsApp group!

 

 

 

 




 

 

 

Comments