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:
💡 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.
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.
Comments
Post a Comment
Share your thoughts...