Python Course Notes
PythonCourse_01_Intro
### Detailed Introduction to Python
Python is a versatile and powerful programming language, ideal for beginners and
experienced developers alike. This section explores the history, features, and real-world
applications of Python.
#### History of Python
- **1989**: Python was conceptualized by Guido van Rossum during his work at CWI in the
Netherlands.
- **1991**: The first version of Python was released.
- **2000**: Python 2.0 introduced new features like list comprehensions.
- **2008**: Python 3.0 was released, making significant improvements.
#### Python Applications
- **Web Development**: Frameworks like Django and Flask.
- **Data Science**: Libraries like Pandas, NumPy, and Matplotlib.
- **Machine Learning**: TensorFlow and PyTorch.
- **Scripting and Automation**: Used for automating repetitive tasks.
#### Exercises
1. Install Python on your machine and verify the installation.
2. Write a Python program to display your name and age.
3. Explore the Python REPL and execute basic commands.
---
### Example Code:
```python
# Python program to display name and age
name = input("Enter your name: ")
age = input("Enter your age: ")
print(f"Hello, {name}. You are {age} years old!")
```
PythonCourse_02_Expressions
### Advanced Details on Expressions
Expressions are building blocks in Python that produce values when evaluated.
#### Types of Expressions
1. **Arithmetic Expressions**
2. **Comparison Expressions**
3. **Logical Expressions**
4. **Compound Expressions**
#### Common Operators and Examples
- `//`: Floor Division
- `%`: Modulus (Remainder)
- `**`: Exponentiation
#### Example Code:
```python
# Arithmetic operations
x = 15
y=4
print("Floor Division:", x // y)
print("Exponentiation:", x ** y)
```
#### Exercises
1. Write a program to calculate the area of a circle using the formula: `Area = π * r^2`.
2. Create a program to determine whether a number is even or odd.
3. Experiment with logical operators (`and`, `or`, `not`) in multiple scenarios.
PythonCourse_03_Conditionals
### Advanced Conditional Statements
Conditional statements allow for decision-making in Python programs.
#### Syntax and Advanced Examples
- Using `elif` for multi-branch decisions.
- Handling user input with conditions.
#### Example Code:
```python
# Check grade based on score
score = int(input("Enter your score: "))
if score >= 90:
print("Grade: A")
elif score >= 75:
print("Grade: B")
elif score >= 60:
print("Grade: C")
else:
print("Grade: F")
```
#### Exercises
1. Write a program to determine if a year is a leap year.
2. Create a program that takes a number as input and outputs whether it is positive,
negative, or zero.
3. Develop a rock-paper-scissors game using conditional statements.
PythonCourse_04_Functions
### Comprehensive Guide to Functions
Functions are essential for code organization and reuse. Learn about function parameters,
scope, and best practices.
#### Example Code:
```python
# Recursive function to calculate factorial
def factorial(n):
if n == 0:
return 1
return n * factorial(n - 1)
print(factorial(5)) # Output: 120
```
#### Exercises
1. Write a function that calculates the Fibonacci sequence up to a given number.
2. Create a program with a function that checks if a string is a palindrome.
3. Develop a temperature converter function (Celsius to Fahrenheit and vice versa).