0% found this document useful (0 votes)
5 views

Python Lesson

Uploaded by

naraji4557
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Python Lesson

Uploaded by

naraji4557
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

Python Lesson 1: Basics of Python Programming

1. Introduction to Python
--------------------------
Python is a high-level, interpreted programming language known for its simplicity
and readability.

2. Variables and Data Types


---------------------------
Variables are used to store data. In Python, you don’t need to declare the type.

Examples:
---------
name = "Alice" # String
age = 25 # Integer
height = 5.6 # Float
is_student = True # Boolean

print(type(name))

3. Basic Input and Output


To print to the console:
print("Hello, world!")

To get input from the user:


name = input("Enter your name: ")
print("Hello, " + name)

4. Conditionals
---------------
Python uses `if`, `elif`, and `else` for decision making.

Example:
--------
age = int(input("Enter your age: "))

if age >= 18:


print("You are an adult.")
elif age > 13:
print("You are a teenager.")
else:
print("You are a child.")

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

You might also like