You are on page 1of 14

Lesson 4

Python Programme
.
. .
: ( ,
)
.
,
. ,

,
( ).
,
,
.
, .
.
.
. ,
:
"" ; .
(.

)\

python

16

1.
.
2.

Python ---IDLE

15

Prepared by John P A for the students and teachers visiting mathsblog.


The English version of the same prepared. by Jomon Johney, KPMVHSS, Poothotta is also available in www.mathsblog.in .


1)
2)

3)

4)
5)

print 45+34
print 45-34
print 34*24
print 5**3
print 25%4

applicationprogramming--IDLE
file new

.
Run run module

1)

a=20
p=4*a
print p

2) input

a=input(enter the side of the square:)

p=4*a
A=a**2
print p
print A
3)
input
n=raw_input("enter your name:)
p=input(Mark in Physics:)

c=input(Mark in chemistry:)
b=input(Mark in biology:)
t=p+c+b
print Total Mark of ,n,=,t

17

PYTHON IDLE

15


19

m=input(enter the mark in Maths:)


if m>19:

Prepared by John P A for the students and teachers visiting mathsblog.


The English version of the same prepared. by Jomon Johney, KPMVHSS, Poothotta is also available in www.mathsblog.in .

Passed
Failed

print Passed
else:
print Failed

d1=input(enter the distance travelled by the


car:)
d2=input(enter the distance travelled by bus:)
t1=input (enter the time taken by the car:)
t2=input(enter the time taken by the bus:)
s1=d1/t1
s2=d2/t2
if s1>s2:
print car is faster than bus
else:
printbus is faster than car

a=input(enter the length of the first rectangle:)


b=input(enter the width of the first rectangle:)
x=input(enter the length of the second
rectangle:)
y=input(enter the width of the second
rectangle:)
A1=a*b
A2=x*y
if x>y:
print area of the first rectangle is more than
the area of the second rectangle
else:
print area of the second rectangle is more
than the area of the first rectangle

A=input(enter the angle A:)


B=input(enter the angle B:)
C=input(enter the angle C:)
D=input(enter the angle D:)
S=A+C
if S==180:
print ABCD is cyclic
else:
print ABCD is not cyclic

2, 3, 5

n=input(enter a number:)
if(n%2)==0 and (n%3)==0 and(n%5)==0:
print n, is a multiple of 2 ,3 and 5
else:
print n, is not a multiple of 2,3 and5

Prepared by John P A for the students and teachers visiting mathsblog.


The English version of the same prepared. by Jomon Johney, KPMVHSS, Poothotta is also available in www.mathsblog.in .

18

range()

range()

Python IDLE

15


(arithmetic
progressions)
output
range() .
(IDLE-
)

:

range() -
.




.

.

range(10)
range(25)
range(1027)

range(1,10)
range(1,10,2)

range(17)
range(0,-10,-1)
range(0,-10,1)
range(0,65,7)
range(10,10)

19

for

for

Python IDLE

15

Prepared by John P A for the students and teachers visiting mathsblog.

The English version of the same prepared. by Jomon Johney, KPMVHSS, Poothotta is also available in www.mathsblog.in .

Programme

Output

print range(1,5)
for number in range(1,5):
print Hello
for name in
[Newton,Galileo,Kepler]:
print name , is a classical
scientist
for number in range(1, 10) :
if (number % 2) == 0 :
print number, " is an
even number."
sum=0
for number in range(1,10):
sum=sum+number
print sum of numbers from 1 to
10 is ,sum
1 100

1 9 .
range(1,11)

sum=0
for number in range(1,100):
if (number%2)==1:
sum=sum+number
print sum of odd numbers from 1 to 100 is , sum

20

Python IDLE

15

Programme

Output

from turtle import *


forward(100)
circle(50)
dot(20,blue)

Prepared by John P A for the students and teachers visiting mathsblog.


The English version of the same prepared. by Jomon Johney, KPMVHSS, Poothotta is also available in www.mathsblog.in .


from turtle import*
pencolor(blue)
pensize(5)
rt(120)
forward(100)
rt(120)
fd(100)
rt(120)
fd(100)

from turtle import *
pencolor(red)
pensize(1)
rt(72)
fd(50)
rt(72)
fd(50)
rt(72)
fd(50)
rt(72)
fd(50)
rt(72)
fd(50)

for
from turtle import *
pensize(5)
pencolor(red)
hideturtle()
for a in range(5):
fd(50)
rt(72)

Prepared by John P A for the students and teachers visiting mathsblog.


The English version of the same prepared. by Jomon Johney, KPMVHSS, Poothotta is also available in www.mathsblog.in .

21

IDLE

15

from turtle import *


circle(50)
circle(60)
circle(70)
circle(80)
circle(90)
circle(100)
from turtle import *
for number in range(10,100,10):
circle(number)

from turtle import *


for i in range(8):
rt(45)
circle(50)

Prepared by John P A for the students and teachers visiting mathsblog.


The English version of the same prepared. by Jomon Johney, KPMVHSS, Poothotta is also available in www.mathsblog.in .

22

for

for
while

IDLE

15

, while

from turtle import *


for i in range(8):
rt(45)
circle(50)
hideturtle()
from turtle import *
i=0
while(i<8):
rt(45)
circle(50)
i=i+1

for i in range(4,40,4):
print i

same result as above

23

Prepared by John P A for the students and teachers visiting mathsblog.


The English version of the same prepared. by Jomon Johney, KPMVHSS, Poothotta is also available in www.mathsblog.in .

IDLE

15

range(15) , range(5,30) ,
range(5,30,3)
range()
.


.range(5,30,3) 5,30,3

.
len("mathsblog.in")
12.

r=range(10) ,
length=len(varapuzha),
r=range(len(www.mathsblog.in)

24

IDLE

15

range, len .
Prepared by John P A for the students and teachers visiting mathsblog.
The English version of the same prepared. by Jomon Johney, KPMVHSS, Poothotta is also available in www.mathsblog.in .

def add(a,b):
sum a+b
return sum

def big(a,b):
if a>=b:
return a
else:
return b

Output

def sum(a,b):
c=a+b
return c
def sub(a,b):
s=a-b
return s
def pro(a,b):
p=a*b
return p
def power(a,b):
q=a**b
return q

25

IDLE

15
Prepared by John P A for the students and teachers visiting mathsblog.

The English version of the same prepared. by Jomon Johney, KPMVHSS, Poothotta is also available in www.mathsblog.in .



1)
2)
3)
4)
5)
6)
7)
8)
9)
10)

a=mathsblog
print a
len(a)
range(len(a))
print a[0]
print a[1]
print a[:2]
print a[2:]
print a.upper()
print a.lower()

1)
2)
3)
4)
5)
6)

a=5+8
a=c+d
a=5+c
a= 5+8
a=5*c
a=5*8

1) a "mathsblog

2) mathsblog
3) a

4) 0 8
5) a
6) a

7) a

8) a

9)MATHSBLOG
10) a =MATHSBLOG mathsblog

3) , 5)

a=O
for i in range(1,11):
print i*a

Prepared by John P A for the students and teachers visiting mathsblog.


The English version of the same prepared. by Jomon Johney, KPMVHSS, Poothotta is also available in www.mathsblog.in .

a=raw_input(enter a word);
n=len(a)
i=1
while (i<n+1):
print a[:i]
i=i+1


while


.
. WxGlade .

26






wxGlade

30

application---programming wxGlade
., ,

add a frame
. wxFrame
ok . design frame


. tree sizer

Prepared by John P A for the students and teachers visiting mathsblog.


The English version of the same prepared. by Jomon Johney, KPMVHSS, Poothotta is also available in www.mathsblog.in .

.
Properties class
. WxFlexGridSizer
ok
sizer1 right addrow, add column

number 1,
number 2

A
.
.properties widget tab
.label 1 number 1 .

Design frame Textbox

add text ctrl ab


.
( add .

)

add a button ok
.
button 1 .
Add . propertiesevents--handler- sum .


(

)

add button
. button
button properties widget

27

Prepared by John P A for the students and teachers visiting mathsblog.


The English version of the same prepared. by Jomon Johney, KPMVHSS, Poothotta is also available in www.mathsblog.in .

wxGlade

30

Tree --application . Properties


.languages
python .
Outputpath
desktop
. .py . generate
code . code generation completed
successfully

double click
run in terminal click

*****code editing ***** .

Prepared by John P A for the students and teachers visiting mathsblog.


The English version of the same prepared. by Jomon Johney, KPMVHSS, Poothotta is also available in www.mathsblog.in .

You might also like