Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg

# Virtual environments
venv/
ENV/
env/
.venv

# IDEs
.vscode/
.idea/
*.swp
*.swo
*~

# OS files
.DS_Store
Thumbs.db

# Testing
.pytest_cache/
.coverage
htmlcov/

# Temporary files
*.log
*.tmp
tmp/
162 changes: 162 additions & 0 deletions 01_Basics/01_variables_and_datatypes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
"""
VARIABLES AND DATA TYPES IN PYTHON
===================================

What are Variables?
-------------------
Variables are containers that store data values.
Think of them as labeled boxes where you can keep different types of information.

Python has several built-in data types:
1. Integer (int) - Whole numbers
2. Float - Decimal numbers
3. String (str) - Text
4. Boolean (bool) - True or False
5. List - Collection of items
6. Dictionary (dict) - Key-value pairs
"""

# ============================================
# NUMBERS (Integers and Floats)
# ============================================

# Integer - whole numbers without decimal points
age = 20
print("Age:", age)
print("Type of age:", type(age)) # type() tells us what kind of data it is

# Float - numbers with decimal points
height = 5.9
print("\nHeight:", height)
print("Type of height:", type(height))

# You can do math with numbers
students = 30
present = 28
absent = students - present
print("\nTotal students:", students)
print("Present:", present)
print("Absent:", absent)


# ============================================
# STRINGS (Text)
# ============================================

# Strings are text enclosed in quotes (single or double)
name = "Alice"
greeting = 'Hello'
print("\n" + greeting + ", " + name + "!")

# You can combine (concatenate) strings with +
first_name = "John"
last_name = "Doe"
full_name = first_name + " " + last_name
print("Full name:", full_name)

# String length
message = "Python is fun!"
print("Message:", message)
print("Length of message:", len(message))


# ============================================
# BOOLEANS (True or False)
# ============================================

# Booleans represent truth values
is_student = True
has_graduated = False

print("\nIs student?", is_student)
print("Has graduated?", has_graduated)

# Booleans are often used in conditions
is_learning_python = True
if is_learning_python:
print("Keep practicing!")


# ============================================
# LISTS (Collections)
# ============================================

# Lists store multiple items in a single variable
fruits = ["apple", "banana", "orange", "mango"]
print("\nFruits list:", fruits)
print("First fruit:", fruits[0]) # Lists start counting from 0
print("Second fruit:", fruits[1])
print("Number of fruits:", len(fruits))

# Lists with numbers
scores = [85, 90, 78, 92, 88]
print("\nScores:", scores)
print("Highest score:", max(scores))
print("Lowest score:", min(scores))


# ============================================
# DICTIONARIES (Key-Value Pairs)
# ============================================

# Dictionaries store data in key-value pairs
student_info = {
"name": "Emma",
"age": 21,
"grade": "A",
"is_active": True
}

print("\nStudent Information:")
print("Name:", student_info["name"])
print("Age:", student_info["age"])
print("Grade:", student_info["grade"])


# ============================================
# TYPE CONVERSION
# ============================================

# You can convert between different data types
number_as_string = "100"
actual_number = int(number_as_string) # Convert string to integer
print("\nString '100' converted to integer:", actual_number)
print("Now we can do math: 100 + 50 =", actual_number + 50)

# Convert integer to string
score = 95
score_text = str(score)
message = "Your score is " + score_text
print(message)


# ============================================
# PRACTICE PROBLEMS
# ============================================

print("\n" + "="*50)
print("PRACTICE PROBLEMS")
print("="*50)

"""
Try these exercises:

1. Create a variable called 'city' and assign your city name to it.
Then print it.

2. Create two number variables and store your age and a friend's age.
Calculate and print the age difference.

3. Create a list of 5 favorite movies and print the list.
Then print only the first and last movie.

4. Create a dictionary to store information about your favorite book:
title, author, year, and pages.
Print each piece of information.

5. Create a string variable with a number like "25", convert it to
an integer, multiply by 2, and print the result.
"""

print("\nTry solving the practice problems above!")
print("Write your solutions in a new file or below this code.")
179 changes: 179 additions & 0 deletions 01_Basics/02_input_output.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
"""
INPUT AND OUTPUT IN PYTHON
==========================

Input: Getting data FROM the user
Output: Showing data TO the user
"""

# ============================================
# OUTPUT - Printing to the screen
# ============================================

print("Hello, World!") # Basic print statement
print() # Empty line for spacing

# Printing multiple items
print("Python", "is", "awesome!")

# Printing with variables
name = "Sarah"
print("Welcome,", name)

# Using f-strings (formatted strings) - Easy and modern way
age = 19
print(f"Hello! My name is {name} and I am {age} years old.")

# Printing with .format() method
city = "New York"
print("I live in {}.".format(city))

# Printing numbers and calculations
x = 10
y = 20
print(f"{x} + {y} = {x + y}")


# ============================================
# INPUT - Getting data from the user
# ============================================

# Basic input - input() always returns a string
print("\n" + "="*50)
print("Let's get some information from you!")
print("="*50 + "\n")

# Getting user's name
user_name = input("What is your name? ")
print(f"Nice to meet you, {user_name}!")

# Getting user's age (need to convert to integer)
user_age = input("How old are you? ")
print(f"You are {user_age} years old.")

# Converting input to integer for calculations
user_age_number = int(user_age)
years_to_30 = 30 - user_age_number
if years_to_30 > 0:
print(f"You will be 30 years old in {years_to_30} years!")
elif years_to_30 == 0:
print("You are exactly 30 years old!")
else:
print(f"You turned 30 about {abs(years_to_30)} years ago!")


# ============================================
# SIMPLE INPUT/OUTPUT PROGRAMS
# ============================================

print("\n" + "="*50)
print("PROGRAM 1: GREETING PROGRAM")
print("="*50 + "\n")

# Get user information
first_name = input("Enter your first name: ")
favorite_color = input("What's your favorite color? ")
favorite_number = input("What's your favorite number? ")

# Display personalized message
print(f"\nHello {first_name}!")
print(f"Your favorite color is {favorite_color}.")
print(f"Your favorite number is {favorite_number}.")
print("Thank you for sharing!")


print("\n" + "="*50)
print("PROGRAM 2: SIMPLE CALCULATOR")
print("="*50 + "\n")

# Get two numbers from user
num1 = input("Enter first number: ")
num2 = input("Enter second number: ")

# Convert strings to numbers
number1 = float(num1) # Using float to handle decimals
number2 = float(num2)

# Perform calculations
addition = number1 + number2
subtraction = number1 - number2
multiplication = number1 * number2
division = number1 / number2

# Display results
print(f"\n{number1} + {number2} = {addition}")
print(f"{number1} - {number2} = {subtraction}")
print(f"{number1} × {number2} = {multiplication}")
print(f"{number1} ÷ {number2} = {division}")


print("\n" + "="*50)
print("PROGRAM 3: AREA CALCULATOR")
print("="*50 + "\n")

# Calculate area of a rectangle
length = float(input("Enter length of rectangle: "))
width = float(input("Enter width of rectangle: "))

area = length * width
perimeter = 2 * (length + width)

print(f"\nArea of rectangle: {area}")
print(f"Perimeter of rectangle: {perimeter}")


# ============================================
# FORMATTED OUTPUT - Making output look nice
# ============================================

print("\n" + "="*50)
print("FORMATTED OUTPUT EXAMPLES")
print("="*50 + "\n")

# Aligning text
print(f"{'Item':<15} {'Price':>10}") # <15 means left-align in 15 spaces
print(f"{'Apple':<15} {'$2.50':>10}")
print(f"{'Banana':<15} {'$1.25':>10}")
print(f"{'Orange':<15} {'$3.00':>10}")

# Formatting decimal numbers
pi = 3.14159265359
print(f"\nValue of Pi: {pi}")
print(f"Pi rounded to 2 decimals: {pi:.2f}") # .2f means 2 decimal places

price = 19.5
print(f"Price: ${price:.2f}") # Ensures two decimal places


# ============================================
# PRACTICE PROBLEMS
# ============================================

print("\n" + "="*50)
print("PRACTICE PROBLEMS")
print("="*50)

"""
Try these exercises:

1. Write a program that asks for your name and your friend's name,
then prints "Hello [your name] and [friend's name]!"

2. Create a program that asks for two numbers and displays their sum,
difference, product, and quotient.

3. Write a program that asks for your birth year and calculates your age
(assuming current year is 2024).

4. Create a program that asks for temperature in Celsius and converts
it to Fahrenheit using the formula: F = (C × 9/5) + 32

5. Write a program that asks for your name, favorite hobby, and how many
hours you spend on it per week. Then print a nice summary message.

6. Create a simple shopping program that asks for item name, quantity,
and price per item, then calculates and displays the total cost.
"""

print("\nTry solving the practice problems above!")
print("Create a new Python file and write your solutions there.")
Loading