Class-IX-Python-Basics
Class-IX-Python-Basics
PYTHON???
He was a big fan
of Britain
Comedy movie-
Monty Python’s
Flying Circus
1.4 Working with Python
Before we start writing a program, we should be thoroughly clear in our mind about
the steps of solving the problem. If we start writing the program without knowing
how to solve the problem, then we can never write the correct program.
This leads to the concept of Computational Thinking.
Boolean Literals:
None is used to indicate absence of value. Also means “there is no useful information” or
“there is nothing here at present”.
OPERATORS in PYTHON
Operators are tokens that trigger some computation when applied to variables and other
objects in an expression.
Variables and objects to which the computation is applied, are called operands.
An operator requires some operands to work upon.
Arithmetic Operators: +, - , * , / , // , % , ** .
Comments are the additional readable information, which is read by the programmers but
ignored by Python Interpreter. Comments begin with Symbol (#).
For example:
# This is a line of comment in our program
# Line 1 of comment
# Line 2 of comment
# Line 3 of comment
Second Method:
‘’’
Text in
Multi lines end with
‘’’
Various Components of a Python program:
Practical: 1
>>> num=25
>>> a=10
>>> num+a
35
>>> var=green
Traceback (most recent call last):
File "<pyshell#32>", line 1, in <module>
var=green
NameError: name 'green' is not defined
>>> var="green"
>>> var
'green'
>>> print(var)
green
>>> print("my favourite colour is " var)
SyntaxError: invalid syntax
>>> print ("my favourite colour is ",var)
my favourite colour is green
>>> print ("my favourite colour is " +var)
my favourite colour is green
Practical: 2
>>> 2+3
5
>>> 5-2
3
>>> 3*2
6
>>> 4/2
2.0
>>> 4//2
2
>>> 5/2
2.5
>>> 5//2
2
>>> 2**2
4
>>> 2**3
8
>>> 4%2
0
>>> 5%2
1
>>> print ("remainder is: ", 5%2)
remainder is: 1
# Empty statement:
age=20
if age>=20:
print(“Eligible”)
else:
pass
1. Simple Statements
2. Compound Statements
4.3 Flow Control Statements:
Revision Assignment
1. Write the extension of python files.
2. Write the different modes in which we can work with python.
3. State the difference between Keyword and Identifier.
4. What are operators? Explain different types of operators.
5. Evaluate: 56/3+6//2*21 [Use operator precedence chart]
6. How many types of strings are supported in Python?
7. What is None literal in Python?
8. What are data types? List Python’s built-in core data types.
9. What is the role of Comments and Indentation in a program.
10. What is a Statement? What is the significance of an empty
statement.
11. How Algorithm is different from a flowchart?
12. Define Variable. Can we use (.) in variable name? [Refer identifier
forming rules]
13. Name the conditional statement in python. Explain its use with an
example.
Practical Assignment
1. Write a python code to input two numbers, find and display their
sum.
2. Write a python code to calculate the radius if diameter is given.
3. Write the python code to calculate the Simple Interest.
4. Input two numbers and swap (interchange) the values.
5. Write a python code to calculate the area of circle and rectangle.
6. Write a python code to calculate the area of circle and rectangle.
[Menu based]
7. Write the python code to input two numbers and print the greatest
one.
8. Write the python code to input a number and display “EVEN” if it is
even otherwise display “ODD” if it is odd.
9. Write a program to input two numbers, find their sum and check if
sum is odd print its cube else print its square.
Practical Test
1. Write a python code to input two numbers, find and display their
sum.
2. Write a python code to calculate the radius if diameter is given.
3. Input age from the user and print if the person is eligible to vote or
not.
4. Write a python code to calculate the area of a rectangle.
5. Write the python code to input two numbers and print the greatest
one.
6. Write a program to input two numbers, find their sum and check if
sum is odd or even.