Day 2: Setting Up Your Coding Space & Writing Your First Python Code!

 

Welcome to Day 2 of 100 Days of Python with Codex Mentis! 🎉 Today, we’ll set up our coding space, explore basic functions, and write our first interactive program while understanding variables and constants.


1️⃣ Choosing an IDE: Where Do We Write Python Code?

An IDE (Integrated Development Environment) is where we write and run Python code. Here are the best options based on your OS:

🔹 Windows & Mac: PyCharm (Powerful but heavier)
🔹 Windows, Mac & Linux: VS Code (Light and customizable)
🔹 Beginners: Thonny (Simple and beginner-friendly)
🔹 Quick & Web-Based: Google Colab (Runs in your browser)

💡 Recommendation: If you’re new, start with Thonny or VS Code.


2️⃣ Your First Python Script

Once you install an IDE, open it and type this:

print("Hello, Python world!")

Then run the script—you should see the message appear! 🎉


3️⃣ Understanding Comments: Your Code’s Sticky Notes

Comments help explain your code. They don’t get executed by Python.

Comments are lines that Python ignores. They help explain your code.

🔹 Single-line comment:

# This is a single-line comment
print("Comments make code readable!")  # This is also a comment

🔹 Multi-line comment:

"""
This is a multi-line comment.
It helps explain the code in detail.
"""
print("Learning Python is fun!")
    

💡 Use comments to document what your code does! 



 

Understanding Data Types in Python

In Python, everything is an object, and these objects have types. Data types define the kind of value a variable can hold and how it behaves when used in operations.


1️⃣ Basic Data Types in Python

1. Strings (str) – Used for text

Strings are sequences of characters enclosed in single ('), double ("), or triple (''' or """) quotes.

name = "Codex Mentis"
print(name)  # Output: Codex Mentis
print(type(name))  # Output: <class 'str'>

📌 Tip: You can concatenate strings using + and repeat them using *.

2. Integers (int) – Whole numbers

Integers represent whole numbers without decimal points.

age = 25
print(age)  # Output: 25
print(type(age))  # Output: <class 'int'> 

3. Floats (float) – Decimal numbers

Floats represent numbers with decimal points.

height = 5.9
print(height)  # Output: 5.9
print(type(height))  # Output: <class 'float'>

4. Booleans (bool) – True or False

Booleans only have two values: True or False. They’re often used in conditions.

is_python_fun = True
print(is_python_fun) # Output: True
print(type(is_python_fun)) # Output: <class 'bool'>



2️⃣ Complex Data Types in Python

5. Lists (list) – Ordered, mutable collection

Lists store multiple values in a single variable and allow modifications.

fruits = ["apple", "banana", "cherry"]
print(fruits) # Output: ['apple', 'banana', 'cherry']
print(type(fruits)) # Output: <class 'list'>

6. Tuples (tuple) – Ordered, immutable collection

Tuples are like lists but cannot be changed once created.

coordinates = (10.4, 20.5)
print(coordinates) # Output: (10.4, 20.5)
print(type(coordinates)) # Output: <class 'tuple'>
 

7. Sets (set) – Unordered, unique values

Sets do not allow duplicate values and are unordered.

unique_numbers = {1, 2, 3, 3, 4}
print(unique_numbers) # Output: {1, 2, 3, 4}
print(type(unique_numbers)) # Output: <class 'set'>
 

8. Dictionaries (dict) – Key-value pairs

Dictionaries store data in key-value pairs for quick lookups.

person = {"name": "Alice", "age": 30, "city": "Nairobi"}
print(person["name"]) # Output: Alice
print(type(person)) # Output: <class 'dict'>

 


 

3️⃣ Type Conversion (Casting)

You can convert data types using built-in functions like int(), str(), and float().

# Convert integer to string

num = 10
num_str = str(num)
print(num_str, type(num_str)) # Output: '10' <class 'str'>


# Convert string to integer

str_num = "20"
int_num = int(str_num)
print(int_num, type(int_num)) # Output: 20 <class 'int'>


# Convert integer to float

float_num = float(int_num)
print(float_num, type(float_num)) # Output: 20.0 <class 'float'>

 


4️⃣ Arithmetic in Python

Python is great at math! Try these in your IDE:

# Basic operations
print(5 + 3)   # Addition
print(10 - 4)  # Subtraction
print(2 * 6)   # Multiplication
print(8 / 2)   # Division (result is always a float)
print(10 // 3) # Floor division (removes decimal)
print(5 % 2)   # Modulus (remainder)
print(2 ** 3)  # Exponentiation (power)


5️⃣ Variables & Constants: Storing Data

Variables store information that can change, while constants hold values that stay the same.

# Variables (Values can change)
name = "Alex"
age = 25
height = 5.9

# Constants (Use UPPERCASE to indicate they shouldn't change)
PI = 3.14159
GRAVITY = 9.8

print(name, age, height)
print("The value of PI is:", PI)


💡 Variables can be updated anytime, but constants remain fixed. Python doesn’t enforce constants, but by convention, we write them in UPPERCASE.


6️⃣ User Input: Making Your Code Interactive 

your_name = input("What is your name? ")
print("Hello, " + your_name + "! Welcome to Python.")


7️⃣ Hands-On Challenge: Create Your Own Profile

📝 Write a small program that asks for a user’s name, age, and favorite color, then prints a fun message.

name = input("What is your name? ")
age = input("How old are you? ")
color = input("What’s your favorite color? ")

print("Hello " + name + "! You are " + age + " years old and you love " + color + ".")


8️⃣ Bonus Challenge: Work with Constants

💡 Now, let’s add a constant to our program! Assume the year is fixed, and calculate how old the user will be in 5 years.

CURRENT_YEAR = 2025 # A constant

name = input("What is your name? ")
age = int(input("How old are you? "))

future_age = age + 5 # Calculating future age

print("Hello " + name + "! In 5 years, you will be " + str(future_age) + " years old.")


📝 Mini-Challenge:

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




📝Setting Up Git & GitHub

Now, let’s save our work in a GitHub repository so we don’t lose it!

Step 1: Install Git

🔹 Windows: Download & install from git-scm.com
🔹 Mac/Linux: Open Terminal and run:

sudo apt install git # Ubuntu/Debian
sudo dnf install git # Fedora
brew install git # Mac (Homebrew)

Step 2: Configure Git

After installing, set your name and email:

git config --global user.name "Your Name"
git config --global user.email "your-email@example.com"

Step 3: Create a GitHub Repository

1️⃣ Go to GitHub and sign in.
2️⃣ Click New Repository → Name it 100DaysOfPython → Click Create

Step 4: Push Your Code to GitHub

In your terminal, navigate to your project folder and run:

git init # Initialize Git
git add . # Add all files
git commit -m "First Python script"
git branch -M main
git remote add origin https://github.com/YOUR_USERNAME/100DaysOfPython.git
git push -u origin main

Now, check your GitHub repo—your code is live! 🎉

 



 




 



 

 

Comments

Popular Posts