Gr-10 Computer Sci Textbook-1-20
Gr-10 Computer Sci Textbook-1-20
CLASS: X
COMPUTER SCIENCE
Chapter - 1
PYTHON
What is Python…?
Differences between program and scripting language
History of Python
Scope of Python
What can I do with python
Who uses python today
Why do people use Python?
Installing Python IDE
A Sample Code
Python code execution
Running Python
What is Python…?
Python is a general purpose programming language that is often applied inscripting
roles.
So, Python is programming language as well as scripting language.
Python is also called as Interpreted language.
Scope of Python:
Science
- Bioinformatics
System
Administration
-Unix
-Web logic
-Web sphere
Web Application Development
-CGI
-Jython –
Servlets Testing
scripts
Downloading and installing Python is free and easy Source code is easily accessible
It's powerful:
Dynamic typing
Built-in types and tools
Library utilities
Third party utilities (e.g. Numeric, NumPy, SciPy) Automatic memory management
It's portable
Python runs virtually every major platform used today
As long as you have compatible Python interpreter installed, Python programs will run in
exactly the same manner, irrespective of platform.
Installing Python
Python is pre-installed on most Unix systems, including Linux and MAC OS X
But for in Windows Operating Systems , user can download from the
https://www.python.org/downloads/
from the above link download latest version of python IDE and install, recent version is
3.6.8, 3.4.1 but most of them uses version 2.7.7 only
1. Download Python distribution
You can download python distribution from the link given below
https://www.python.org/downloads/
Note –Download only that python distribution/MSI Installer, which is best suited for the
Operating system on which you want to install it.
2. Python installation process
Double-click the icon labeling the file<version>.exe
Popup window will appear
5. A new Python <version> Setup pop-up window will appear with a Setup Progress
message and a progress bar.
• Click start button All programs Python 3.6x IDLE (Python GUI)
(or)
• Click start button All programs Python 3.6x Python (Command line)
2. In Python shell window (python command prompt appears as >>>)
3.Type commands in front of the Python prompt and Python will immediately give the result.
In Interactive mode ,instructions are given in front of python prompt in python shell.
Interactive mode does not save commands in form of a program.
It is suitable for testing code.
Type commands in front of the Python prompt and Python will immediately give the result.
OPERATOR IN PYTHON
Arithmetic Operators:
• Basic Arithmetic Operators are:
• +
• -
• *
• /
• //
• %
• **
The division operator /
The /operator always returns the result as float value
• 12/26.0
• 100/1010.0
• 7/2.52.8
• 12//26
• 100//1010
• 100.0//1010.0
• 100%100
• 7.2%31.2
• 4**364
• 36**.56.0
• 10.0**201e+20
Relational Operators
The relational operator compares two expression and results in either True or False.
• <
• >
• <=
• >=
• ==
• !=
Logical Operators
• While relational operators establishes the relationship among values, logical operators refers to
the ways these relationships can be connected.Python provides three logical operators to
combine existing expressions. These are:
• and
• not
• or
VARIABLES IN PYTHON
Variable
Create a Variable:
>>>headmaster=“Dumbledore”
>>>print (headmaster)
Dumbledore
>>>print (headmaster)
Hardcastle
o String “Whoop”
o Integer 42
o Float 3.14159
<type ‘str’>
STRINGS IN PYTHON
Strings
Lists
Index: Where an item is in the list
>>> Beatles = [“John”, “Paul”, “George”, “Ringo”]
>>> Beatles[0]
‘John‘
0 1 2 3
Practical Notes
1. Simple Programs
2. creating python with .PY extension
3. Odd or Even number
4. Print Natural Numbers
5. WAP to find person is eligible to vote or not.
6. WAP to print 5,10,15 tables
7. Uses of different types of variable in Python
Chapter 2
LOOPS & CONDITIONAL STATEMENTS
Statement Description
if statements An if statement consists of a boolean expression
followed by one or more statements.
Loop type
Loop Type Description
while loop Repeats a statement or group of statements
while a given condition is TRUE. It tests the
condition before executing the loop body.
For loop Executes a sequence of statements multiple
times and abbreviates the code that manages the
loop variable.
Nested loop You can use one or more loop inside anyanother
while, for or do..while loop.
CONDITIONAL STATEMENTS (Decision Making)
• if statement
• if...else statement
• if...elif...else staement
The if statement
The if statement is a decision-making statement. It is used to control the flow of execution of
thestatements and also used to test logically whether the condition is true or false.
Syntax
if test expression:
statement(s)
Example program
i =int(input(“Enter the number:”))
if(i<10):
print(“condiotion is true”)
OUTPUT
Condition is true
If … else statement
The if…else statement is called alternative execution, in which there are two possibilities and the
condition determines which one gets executed.
Syntax
if test expression:
Body of if
else:
Body of else
SYNTAX
If expression:
Body of if
elif
expression:
Body of elif
else:
Body of else
Figure – elif condition Flowchart:
if expression1:
statement(s)
if expression2:
statement(s)
elif expression3:
statement(s)
else:
statement(s)
Example program
n= int(input(“Enter
if(n<=15):
if (n == 10):
OUTPUT
print(‘play cricket’)
Enter number:10
else:
print(‘play kabadi’) play cricket
else:
print(‘Don’t play game’)
These are repetitive program codes, the computer have to perform to complete tasks. The
following are the loop structures available in python.
while statement
while expression:
statement(s)
The for loop in Python is used to iterate over a sequence (list, tuple, string) or
other iterable objects. Iterating over a sequence is called traversal.
Syntax
for val in sequence:
Body of for loop
Break statement
Continue statement
Pass statement – It is an empty statement do nothing. It is generally used as a placeholder.