Python Notes For 9 Final
Python Notes For 9 Final
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.
#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')
#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')
#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')
#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)