Python Lesson
Python Lesson
1. Introduction to Python
--------------------------
Python is a high-level, interpreted programming language known for its simplicity
and readability.
Examples:
---------
name = "Alice" # String
age = 25 # Integer
height = 5.6 # Float
is_student = True # Boolean
print(type(name))
4. Conditionals
---------------
Python uses `if`, `elif`, and `else` for decision making.
Example:
--------
age = int(input("Enter your age: "))
5. Loops
--------
a. While Loop
-------------
count = 0
while count < 5:
print("Count is:", count)
count += 1
b. For Loop
-----------
for i in range(5):
print("i is:", i)
6. Functions
------------
Functions help organize code into reusable blocks.
Example:
--------
def greet(name):
print("Hello, " + name + "!")
greet("Alice")
7. Practice Task
----------------
- Write a program that asks the user for a number.
- If the number is even, print "Even".
- If the number is odd, print "Odd".
Sample Code:
------------
number = int(input("Enter a number: "))
if number % 2 == 0:
print("Even")
else:
print("Odd")
8. Summary
----------
- Python uses indentation instead of braces.
- Variables are dynamically typed.
- Functions are defined using `def`.
- Common structures include conditionals (`if`) and loops (`for`, `while`).
End of Lesson 1