Grade-9 - PYTHON Programming
Grade-9 - PYTHON Programming
● Features of Python
● Limitations of Python
● Working with Python
● Python Tokens
● Data-types in Python
● Statements in Python Programs
● Expressions in Python
● Accepting User Input and Displaying Output in Python
What is Python?
It is used for:
Ever wo
ndered
create s how do
uch prog people
rams?
To develop a program,
❖ The very first step that comes into the picture is to specify the
task which the machine needs to do.
❖ Once the task or the main objective of the program is finalized, the
task is broken into smaller tasks.
❖ Finally all together contribute towards achieving the main goal.
Can you think of other ways to make instant noodles? Write them down.
Write algorithms for the challenges given.
Conclusion:
● Python Tokens
● Data-types in Python
● Expressions in Python
“”” ………………….
………………….. “”” - Multi line comments
A comment is text that doesn't affect the outcome of a code, it is just a piece of text to
let someone know what you have done in a program or what is being done in a block
of code.
Keywords are the
reserved words in
Python used by
Python interpreter to
recognize the
structure of the
program.
Identifiers
Literals:
1. Numeric Literals
● Integers ( 23, -45)
● long int with unlimited size.
● Floating point - decimal values
● Complex literals - 2+3j
complex([real[, imag]])
x = complex(2,3)
>>>print(x)
>>>(2+3j)
2. Character Literals - ‘ ‘ or “ “ - ‘a’,’4’,’#’
3. String Literals - Single,Double & Triple quotes
4. Boolean Literals - True or False
print(bool("Hello")) -> True
>>> print(10 > 9) -> True
print(bool(15)) -> True
>>>print(10 == 9) -> False
print(bool()) -> False
6. Collection Literals:
● List collections - [abc,xyz,pqr]
● Tuple collection - (23,56,89)
● Dictionary collections
{‘a’:”apple”,’b’:”ball”,’c’:”cat”}
● Set collections {‘a’,’b’,’c’}
Python Operators -
❖ Operators are special symbols which represent computation.
❖ Value and variables when used with operator are known as operands.
Arithmetic Operators
3000
3.0
Conditional Operators
Logical Operators
Assignment Operators
Statements in python
Output Statements -
print(“hello python”)
print(a)
print(23,45,36)
print(“The value is “, a)
x=”python” print(“This is “ + x)
Input statements -
String:
a=input(“enter your name:”)
b=input(“enter your grade:”)
Numeric:
1. a=int(input(“Enter the value of a:”))
c=a+b
a,b,c=5,6.7,”APPLE”
a=b=c=5
a=int(z)
print(x) print(a) 6
print(y)
print(float(y)) 4.0
print(z)
print(a,b,c)
print(type(x))
print(type(c))
print(type(z))
Try it out….
Declare 5 variables in a single line declaration, with numeric whole numbers for
first 2 and decimal value for the 3rd variable. The 4th & 5th variable should be
string value.
1. Multiply the 1st & 3rd variable and display the output.
2. Concatenate the 4th & 5th variable and display the output.
3. Combine the 1st and 5th variable and display the output.
4. Convert the decimal variable to a whole number and display.
5. Convert the 2nd variable into a decimal value and display it with its datatype.
Conditional Statements
● While coding in Python, a lot of times we need to take decisions.
● In this case, we need the machine to understand what should happen when.
This is where conditional statements help.
● Conditional statements help the machine in taking a decision according to
the condition which gets fulfilled.
There exist different types of conditional statements in Python.
According to the number of conditions and their dependency on each other, the relevant type of
conditional statement is used.
If statement in PYTHON
if condition : if condition 1 :
Stmt 1 Stmt 1….
elif condition 2 :
Stmt 2…
elif condition 3:
Stmt 3…
If condition : else:
Stmt ...
Stmt 1...
else :
Stmt 2 ….
Example - If statement in PYTHON
#if statement
a=(input("Enter ur choice"))
a=50,b=10
if a == "pizza" :
if a>b: print("\n You have ordered pizza")
print(a) elif a== "burger":
else: print("\n You have order burger")
print(b) else :
print("\n Pls order again")
Example - If statement in PYTHON
print( ...) if condition else print (....) if condition else print (...)
# 3 conditions example
a=8001
b=8008
print("a >") if a>b else print ("equal") if a==b else print("b >")
Link
Logical AND & OR in if stmt
a=7,b=69,c=80
if a>b and c>a:
print("c is >")
else:
print("*****")
Link
❏ Accept the age of a person and check whether the person is a senior citizen or not.
if age>=60:
else:
1. If the unit consumed is less or equal to 100 units, calculates the total amount of consumed
= units*1.5
2. If the unit consumed between 100 to 200 units, calculates the total amount of consumed
=(100*1.5)+(unit-100)*2.5
3. If unit consumed between 200 to 300 units, calculates total amount of consumed
=(100*1.5)+(100*2.5)+(units-200)*4
4. If unit consumed between 300-400 units, calculates total amount of consumed
=(100*1.5)+(100*2.5)+(100*4)+(units-300)*5
5. If unit consumed is > 400 units, calculates total amount of consumed
=(100*1.5)+(100*2.5)+(100*4)+(100*5)+(units-400)*8
Condition for Meter charges apply
if units > 200 and units < =300, Meter charges = Rs.75.00
if units > 300 and units < =400, Meter charges = Rs.100.00
if units above 400, No Meter charges (Rs.00) but Standard Additional charge of
Rs.500/- is applicable.
~~~~~~~~~Tamil Nadu Electricity Board~~~~~~~~~~~
Coimbatore District
Date:
p le Consumer no:2324255
a m ut Name: Shiva
S tp Units consumed: 500
Ou r nce …………………………………………………………………………………………………….
o
F fer e Unit Charges in Rs : xxxx
re Meter Charges in Rs: 75
Additional charge in Rs: 500
*****Save Electricity*****
Loops in Python
● while loops
● for loops
Python programming language provides above types
of loops to handle looping requirements.
for x in “Hai”: H
Syntax:
print(x) a
for var in iterable:
i
# statements fruits = ["apple", "banana", "cherry"]
apple
for x in fruits:
banana
print(x) cherry
1
nos=[1,2,3,4,5]
2
for x in nos: 3
print(x) 4
5
Can you try creating….
Output: Output:
apple apple
mango mango
cherry
for loop with range( ) Function
for x in range(5): for x in range(5):
Output:
print(x) if x == 3
0
else: break 1
2
print("Loop Completed") print(x)
else:
6 8
7 9
9
Nested for loop
Output:
no = [1,2,3,4] 1 apple
1 banana
fruits = ["apple", “banana", "cherry"]
1 cherry
2 banana
for y in fruits:
2 cherry
print(x,y) 3 apple
3 banana
3 cherry
4 apple
4 banana
4 cherry