Python Programming Basic
Aye Nandar Hlaing
PhD (IT)
09 Python Basics, Data Types & Operators
Python Programming Basic
What will you learn today?
Understand Python basics
Use input and output
Work with variables
Understand data types
Use operators
Python Programming Basic
What is Python?
• A programming language
• Easy to read and write
• Used in AI, apps, data science
3/21
Python Programming Basic
Displays output
• print() shows output
• Text must be in quotes
print("Hello, Student!") print(‘Hello, Student!’)
print("Hello, World!") print(‘Hello, World!’)
print("My name is Rosy.") print(‘My name is Rosy.’)
4/21
Python Programming Basic
Input
• input() gets user data
• Stored in a variable
e.g.,
name = input("Enter your name: ")
print(name)
name = input("Enter your name: ")
print("Hello", name)
5/21
Python Programming Basic
Variables
• Store data
• = means assign value
e.g.,
age = 20
name = "Luna“
Mark = 80
6/21
Python Programming Basic
Variable Rules
• No spaces
• Cannot start with number
• Use meaningful names
Check
e.g.,
my_account11
my_name ✔
11_Id
7user ❌
total_mark
mark ✔
User_18
123User
7/21
Python Programming Basic
Practice
name = input("Enter your name: ")
age = input("Enter your age: ")
print("Name:", name)
print("Age:", age)
8/21
Python Programming Basic
What is data type?
• Types of data stored in a variable
Integer (int): e.g., age = 20
Float (float): e.g., price = 10.5 input() always returns string
String (str): e.g., name = “Amlie“
Boolean (bool): e.g., is_valid = True
9/21
Python Programming Basic
Type Conversion
• Convert string → integer
Let’s check the following examples.
e.g.,
e.g.
loan = input("Enter loan amount: "))
age = int(input("Enter age: "))
print(‘Loan amount ‘, loan)
print(age)
interest_rate = input("Enter interest rate: "))
print(‘Interest rate’, interest_rate)
interest = loan * interest_rate
print(‘Interest ‘, interest)
10/21
Python Programming Basic
Arithmetic Operators
Operator Meaning
+ Add
- Subtract
* Multiply
/ Divide
11/21
Python Programming Basic
Arithmetic Examples
a = 10
b=5
print(a + b)
print(a * b)
C=a+b
print(‘a+b is ‘, C)
12/21
Practice Tasks Python Programming Basic
Q1 Ask the user for name and city and then print the input.
Q2 Write a python program to input two numbers, add them and print the result.
Q3 Ask the user to input three numbers, calculate average and print the result.
13/21
Python Programming Basic
Comparison Operators
Operator Meaning
Comparison Examples
> Greater
< Less print(10 > 5)
== Equal print(10 == 5)
!= Not equal print(10 > 5)
print(10 < 5)
a = 10
print(a == 123)
print(10 != 5)
14/21
Python Programming Basic
Logical Operators
AND → both true
OR → one true
Logical Examples
NOT → opposite
print(10 > 5 and 5 > 2) # True
print(10 > 5 and 5 < 2) # False
print(10 > 5 or 5 < 2) # True
print(10 < 5 or 5 < 2) # False
print(not(10 > 5)) # False
15/21
Python Programming Basic
Practice
num1 = int(input("Enter number: "))
num2 = int(input("Enter number: "))
print("Sum:", num1 + num2)
print("Greater?", num1 > num2)
16/21
Python Programming Basic
Activity
Q4 Ask the user for marks of three subjects, calculate total and average and then print them.
Q5 Ask the user for marks of two subjects. If both are greater than or equal to 50, print “Pass”. Otherwise,
print “Fail”.
17/21
Python Programming Basic
Common Mistakes
Forget int()
Use = instead of ==
Mix string + number
18/21
Python Programming Basic
Recap
What is a variable?
What is a data type?
What does input() return?
What is ==?
19/21
Python Programming Basic
Summary
print() → display output
input() → get user input
• t
Variables → store data
Data Types: int, float, string, boolean and etc.
Operators: Arithmetic, Comparison, Logical
20/21
Python Programming Basic
Next Lesson
Data Handling & Checking
Thank you