100% found this document useful (1 vote)
8K views

Python Notes For 9 Final

Python is a high-level programming language well-suited for AI and data applications. It has rich libraries for handling and manipulating data. Python can be downloaded from the official website and used in various integrated development environments like IDLE, PyCharm, and Jupyter. Python code is written in scripts that can perform tasks like calculations, take user input, and print output. Common data types in Python include integers, floats, strings, and lists.

Uploaded by

Mahima Kalucha
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
8K views

Python Notes For 9 Final

Python is a high-level programming language well-suited for AI and data applications. It has rich libraries for handling and manipulating data. Python can be downloaded from the official website and used in various integrated development environments like IDLE, PyCharm, and Jupyter. Python code is written in scripts that can perform tasks like calculations, take user input, and print output. Common data types in Python include integers, floats, strings, and lists.

Uploaded by

Mahima Kalucha
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 18

PYTHON FOR CLASS 9

Python is a high-level programming language, well suited for handling data


through its rich libraries of modules where programmers can create their own
programs. AI is data driven so python is first choice to develop applications
related with data handling and manipulation.

Versions 2.X and now 3.X have been popular and python 3.X is the most
adopted version in industry today.
It’s a free and an open-source software, where source code files are freely
available to add new features.
Getting python:
Python can be downloaded from https://www.python.org/downloads and the
version is 3.8 onwards.
When its installed, open python folder in start menu and click on IDLE python
3.8.
Python IDLE: IDLE is python’s Integrated Development and Learning
Environment. It allows interactive as well as script modes to work with python
interpreter. It provides an editor to write and edit your scripts(programs) and to
save them. Python shell is built into IDLE which interprets the commands and
scripts submitted to it.
Python Script Mode: In this mode, python commands are saved in a logical
order to get desired output. This logical set of instructions is called
script(program). Once the script is saved, it can be executed anytime. Python
script files have extension .py.
Some popular opensource python IDEs are:
• PyCharm by JetBrains
• Spyder, Atom by MIT
• Jupyter by jupyter.org
• Microsoft Visual Studio Code

Python examples:
Fun with Numbers:
>>> 2+2
4
>>> 43-7
36
>>>15/2
7.5
>>>5%2
1
>>>4**3
64
>>>17/3
5.666666666667
Fun with strings:
Strings are characters or letters in a sequence. Strings are enclosed within
double quotes like “Delhi”,” 12345”, “Ranchi”,” DL 29 SD 1678”.
Any sequence of letters within quotes is treated as a string. Avoid
enclosing one single quote within a pair of single quotes.

Eg: 1. Print (”Hello World”)


2. print (“ Ruchi Dhiman”)

IDLE Script Mode:


Click file menu---new file or ctrl+ N
A new window appears. After writing code
Click file menu--------save as
Then give a name to your file with .py
E.g.: ab.py, abc.py
then click---run ---run module or F5 key
Python Statements:
A program statement is the instruction written in program to execute
certain type of code. There are certain number of lines written in the code to
execute some specific tasks. These lines are known as statements.
Example, The programmer want to print the product of 5 and 6, then he will
write something like this:
print(5 * 6) output: 30
Print Function:
Its used for printing the information on the screen.
Eg: print(message/value)
For messages, enclose them in quotes.
Numbers or integers:
These are plain positive or negative numbers. They are not enclosed in quotes.
Eg: age=12
Height=20
X=10
Strings: Text is called strings. They are enclosed in quotes.
Eg: “hello”
“I am a Python fan”
Floats: Numbers with decimal places are called floats. They can store up to 15
decimal places.
X=7.3
Y=6.3e4
Eg:
1)N=input (“what is your name?”)
Print (“welcome”, n)
2) A=input (“enter a number”)
B= input (“enter another number”)
Print(a+b)
Dual role of + operator: we know that an arithmetic operator is used for
addition.
Eg:
a=input (“enter a number”)
b= input (“enter another number”)
print(a+b)
By default, it takes the input as strings and it concates it.so, if we enter 20 and
12, output is 2012.
Now if we want the sum of above then
a=input (“enter a number”)
b= input (“enter another number”)
print (“answer is:”, int(a)+int(b))
This is explicit conversion.
Python automatically does data conversion known as implicit data type
conversion.
Eg: 2*3.5
The result will be in float datatype since data conversion is automatically taken
care of.
Eval(): It parse the expression argument and evaluate it as a python expression and
runs python expression(code) within the program.
Eg: eval(expression)
LIST:
List is a sequential data structure. It’s an ordered collection of values. It’s
declared by using a pair of square brackets. []
Eg: states [], names [], animals [] etc.
Types of lists:
1. Empty list: it’s created by python in-built function list ().
Eg: states=list ()
2. String list: which contains string as parameter.
Eg: mylist=list(“hello”)
3. List storing different data values
Eg: mylist= [23,’apple’,53.4,5,” Zebra”]
SOLVED EXAMPLES:
#1)to add 2 no.
print('to add 2 no.')
a=eval(input('Enter your first no. '))
b=eval(input('Enter your second no. '))
r=a+b
print('The sum of the numbers is ',r,)

#2)to add 4 no.


print('to add 4 no.')
a=eval(input('Enter your first no. '))
b=eval(input('Enter your second no. '))
c=eval(input('Enter your third no. '))
d=eval(input('Enter your fourth no. '))
r=a+b+c+d
print('The sum of the numbers is ',r)

#3)to multiply 3 no.


print('to multiply 3 no.')
a=eval(input('Enter your first no. '))
b=eval(input('Enter your second no. '))
c=eval(input('Enter your third no. '))
r=a*b*c
print('The product of the numbers is ',r)

#4) average of 5 no.


print('avg of 5 no.')
a=eval(input('Enter your first no. '))
b=eval(input('Enter your second no. '))
c=eval(input('Enter your third no. '))
d=eval(input('Enter your fourth no. '))
e=eval(input('Enter your fifth no. '))
r=(a+b+c+d+e)/5
print('The average of the numbers is ',r)

#5) age after 15 yrs


print('age after 15 yrs')
age=int(input('Enter your age '))
nage=age+15
print('Your age after 15 years is ',nage,'years')
#6) a cube no.
print('a cube no.')
a=eval(input('Enter your no. '))
r=a**3
print('The cube of the number is ',r)

#7)area of a square
print('area of a square')
a=eval(input('Enter the lenght of the square '))
area=a**2
print('The area of the square is ',r,'sq.units')

#8)area of a rectangle
print('area of a rectangle')
a=eval(input('Enter the lenght of the rectangle '))
b=eval(input('Enter the breadth of the rectangle '))
area=a*b
print('The area of the rectangle is ',area,'sq.units')

#9)x**N or pow(x,n)
print('x**N or pow(x,n)')
a=eval(input('Enter your base no.(X) '))
b=eval(input('Enter your exponent no.(N) '))
r=a**b
print('the answer is ',r,'\n')
#10)perimeter of a rectangle
print('perimeter of a rectangle')
a=eval(input('Enter the lenght of the rectangle '))
b=eval(input('Enter the breadth of the rectangle '))
perimeter=2*(a+b)
print('The perimeter of the rectangle is ',perimeter,'units')

#11) area of a circle


print('area of a circle')
radius=eval(input('Enter the radius of the circle '))
area=3.14*r*r
print('The area of the circle is ',area,'square units')

#12)circumference
print('circumference')
radius=eval(input('Enter the radius of the circle '))
circumference=2*3.14*r
print('The circumference of the circle is ',circumference, 'units')

#13)converting hours and minutes into seconds


print('converting hours and minutes into seconds')
hours=eval(input('enter hour/s'))
minutes=eval(input('enter minute/s'))
seconds=eval(input('enter second/s'))
hours=hours*60*60
minutes=minutes*60
tseconds=hours+minutes+seconds
print('the time in seconds is ',tseconds,'sec')

#15)increasing 25% of the cost


print('increasing 25% of the cost')
cost=eval(input('Enter cost '))
ncost=cost+cost*0.25
print('the new cost after increasing 25% is',ncost,'bucks')

#16) a square no.


print('square no.')
a=eval(input('Enter your no. '))
r=a**2
print('The square of the number is ',r)

#17)volume of a sphere
print('volume of a sphere')
radius=eval(input('enter the radius of the sphere'))
vol=(4/3)*3.14*r**3
print('the volume opf the sphere is ',vol,'cube units')

#18)area of a triangle using heron's formula


print("area of a triangle using heron's formula")
a=eval(input('Enter the first side of the triangle '))
b=eval(input('Enter the second side of the triangle '))
c=eval(input('Enter the third side of the triangle '))
s=(a+b+c)/2
e=s*(s-a)*(s-b)*(s-c)
area=e**0.5
print("The area of the triangle using hero's formula is ",area,'sq.units')

#19)Compound interest
print('Compound interest')
p=eval(input('Enter the principal amount '))
r=eval(input('Enter the rate of interest '))
t=eval(input('enter the time in years '))
ci=p*(1+(r/100))**t
print('the compound interest for the given values is', ci)

#20)Average of marks and percentage


print('average of marks and percentage')
s1=float(input("Enter your English Marks : "))
s2=float(input("Enter your Physics Marks : "))
s3=float(input("Enter your Chemistry Marks : "))
s4=float(input("Enter your Maths Marks : "))
s5=float(input("Enter your Biology Marks : "))
total=s1+s2+s3+s4+s5
avg=total/5
percentage=(total*100)/5
HANDS ON PRACTICE:
1. Calculate 3% discount on the amount entered by the user. The output should
be as
The discount on <<amount>> is <<amount after discount >>.
2.There is a farm of circular shape. Accept radius from the user and calculate its
area.
3. The basic salary of a person is 12000.deductions are:
HRA -9% of basic
PF-12% of basic
Allowances – 125% of basic
Other incentives-10% of basic.
Calculate his net salary and display the output:
Net salary=(Basic +DA+ Incentives)-(HRA+PF)

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy