Program No:1 Aim: Find The Sum of N Natural Numbers Author: Varchasava Yadav Roll No 32 Class XIC

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 46

Program No:1

Aim: Find the sum of N Natural numbers

Author: Varchasava yadav Roll No 32 Class XIC


n=eval(input("enter the n number"))

i=1

sum=0

while(i<=n):

sum=sum+i

i+=1

print("sum of n natural number=",sum)

output

enter the n number 5

sum of n natural number= 15


Program No: 2

Aim: Boolean literals

Author: Varchasava yadav Roll No 32 Class XIC

x=(1== True)

y=(1== False)

a=True + 4

b=False + 4

print("x is",x)

print("y is",y)

print("a:",a)

print("b:",b)

output

x is True

y is False

a:5

b:10
Program No: 3

Aim: constant

Author: Varchasava yadav Roll No 32 Class XIC


import modull

print(modull.pi)

print (modull.gravity)

output

3.14

9.8
Program No: 4

Aim: Keywords

Author: Varchasava yadav Roll No 32 Class XIC


import sys

import keyword

print(" python version: ",sys.version_info)

print(" python keywords: ", keyword.kwlist)

output

python version: sys.version_info(major=3, minor=6, micro=4, releaselevel='final', serial=0)

python keywords: ['False', 'None', 'True', 'and', 'as', 'assert', 'break', 'class', 'continue', 'def', 'del',
'elif', 'else', 'except', 'finally', 'for', 'from', 'global', 'if', 'import', 'in', 'is', 'lambda', 'nonlocal', 'not', 'or',
'pass', 'raise', 'return', 'try', 'while', 'with', 'yield']
Program No: 5

Aim: Literal collection

Author: Varchasava yadav Roll No 32 Class XIC


fruits=["apple","mamgo","orange"]#list

number=(1,2,3)#tuple

alphabets= {'a':'apple','b':'ball','c':'cat'}#dictionary

vowels= {'a','e','i','o','u'}#set

print(fruits)

print (numbers)

print (alphabets)

print (vowels)

output

['apple','mango',oranges']

{'a':'apple','b',ball,'c':'cat'}

{'e','o','a','u','i'}
Program No:6

Aim: Find The Sum And Averages Of 5 number

Author: Varchasava yadav Roll No 32 Class XIC


n1=eval(input("enter the first number"))

n2=eval(input("enter the second number"))

n3=eval(input("enter the third number"))

n4=eval(input("enter the forth number"))

n5=eval(input("enter the fifth number"))

sum=n1+n2+n3+n4+n5

avg=sum/5

print("sum and average of 5 number are:",sum,avg,sep="@")

output

enter the first number 5

enter the second number 5

enter the third number 5

enter the forth number 5

enter the fifth number 6

sum and average of 5 number are:@[email protected]


Program No: 7

Aim: module

Author: Varchasava yadav Roll No 32 Class XIC


pi=3.14

gravity=9.8

OUTPUT

[evaluate modull.py]
Program No:8

Aim: numerical literals

Author: Varchasava yadav Roll No 32 Class XIC


a=0b1010

b=100#decimal literal

c=0o310#octal literal

d=0x12c#hexadecimal literal

#float literal

float_1=10.5

float_2=1.5e2

#complex literal

x=3.14j

print(a,b,c,d)

print(float_1,float_2)

print(x,x.imag,x.real)

output

10 100 200 300

10.5 150.0

3.14j 3.14 0.0


Program No: 9

Aim: To Find that all sides are forming a triangle or not if they are forming
the triangle then which type of triangle it is.

Author: Varchasava yadav Roll No 32 Class XIC

import math

s1=eval(input("enter the first side "))

s2=eval(input("enter the second side"))

s3=eval(input("enter the third side"))

if(s1+s2>s3)or(s2+s3>s1)or(s3+s1>s2):

print ("three side are forming the triangle")

if (s1==s2)and(s2==s3)and(s3==s1):

print ("equilateral triangle")

elif(s1==s2)or(s2==s3)or(s3==s1):

print("isoceleus triangle")

elif (s1!=s2)and (s2!=s3)and(s3!=s1):

print ("scalene triangle")

elif(math.pow(s1,2)+math.pow(s2,2)==math.pow(s3,2))or
(math.pow(s2,2)+math.pow(s3,2)==(s1,2))or(math.pow(s3,2)+math.pow(s1,2)==math.pow(s2,2)):

print ("right triangle")

sp=(s1+s2+s3)/2

a=main.sqrt(sp*(sp-s1)*(sp-s2)*(sp-s3))

print(sp)

print(a)

else: print (" the number not forming a triangle")

output

enter the first side 2


enter the second side 2

enter the third side 2

three side are forming the triangle

equilateral triangle
Program No:10

Aim: Find the sum of n natural no

Author: Varchasava yadav Roll No 32 Class XIC


n=eval(input("enter the n number"))

i=1

sum=0

while(i<=n):

sum=sum+i

i+=1

print("sum of n natural number=",sum)

output

enter the n number 5

sum of n natural number= 15


Program No: 11

Aim:Find the age of a person

Author: Varchasava yadav Roll No 32 Class XIC

cy=eval(input("enter the current year"))

cm=eval(input("enter the current month"))

cd=eval(input("enter the current day"))

by=eval(input("enter the birth year"))

bm=eval(input("enter the birth month"))

bd=eval(input("enter the birth date"))

if(cd<bd):

if(cm==1)or(cm==3):

cd=cd+31

cm=cm-1

elif(cm==4)or(cm==6):

cd=cd+30

cm=cm-1

if(cy%4==0):

cd=cd+29

cm=cm-1

else:cd=cd+28

cm=cm-1

if(cm<bm):

cm=cm+12

cy=cy-1

nd=cd-bd
nm=cm-bm

ny=cy-by

print("you are=",ny,nm,nd,sep=('_'))

output

enter the current year2018

enter the current month9

enter the current day17

enter the birth year2001

enter the birth month6

enter the birth date20

you are=_17_3_-3
Program No: 12

Aim: Find the sum of first n natural no

Author: Varchasava yadav Roll No 32 Class XIC

n=eval(input("enter the n number"))

sum=0

for i in range(1,n+1):

sum=sum+i

print("sum of n natural number=",sum)

output

enter the n number 5

sum of n natural number= 15


Program No: 14

Aim: Find that given year is a leap year or not

Author: Varchasava yadav Roll No 32 Class XIC

year=eval(input("enter the year"))

if (year % 4==0):

print ("given year is leap year")

else:

print ("given year is not leap year")

output

enter the year 16

given year is leap year


Program No: 15

Aim: Find the sum of first odd natural no

Author: Varchasava yadav Roll No 32 Class XIC


n=eval(input("enter the n number"))

i=1

sum=0

while(i<=n):

sum=sum+i

i+=2

print("sum of first odd number=",sum)

output

enter the n number 5

sum of first odd number= 9


Program No: 16

Aim: Enter the selling price and cost price of a transection and also find
that transection is no profit or no loss or profit or loss

Author: Varchasava yadav Roll No 32 Class XIC


sp=eval(input("enter the selling price"))

cp=eval(input("enter the cost price"))

if sp==cp:

print ("no profit no loss")

elif sp>cp:

print("profit")

profit=sp-cp

profitpercentage=(profit/cp)*100

print("profit=",profit)

print("profit percentage =",profitpercentage)

else:

print("loss")

loss= cp-sp

losspercentage=(loss/cp)*100

print("loss")

print("loss percentage =",losspercentage)

output

enter the selling price 50

enter the cost price 50

no profit no loss
Program No: 17

Aim: Find the sum of odd and even natural no

Author: Varchasava yadav Roll No 32 Class XIC


N=int(input("Enter the number"))

sum1=0

sum2=0

for i in range(1,N+1,2):

sum1=sum1+i

print("sum of n odd natural number =",sum1)

for i in range (0,N+1,2):

sum2=sum2+i

print("sum of even natural number =",sum2)

output

Enter the number5

sum of n odd natural number = 9

sum of even natural number = 6


Program No: 18

Aim: Find the largest and the smallest no

Author: Varchasava yadav Roll No 32 Class XIC


a=eval(input("enter the first number"))

b=eval(input("enter the second number"))

c=eval(input("enter the third number"))

d=eval(input("enter the forth number"))

ln=a

if b>ln:

ln=b

elif c>ln:

ln=c

else:

ln=d

print("largest number=",ln)

a=eval(input("enter the first number"))

b=eval(input("enter the second number"))

c=eval(input("enter the third number"))

d=eval(input("enter the forth number"))

sln=a

if b<sln:

sln=b

elif c<sln:

sln=c

else:

sln=d
print("second largest number=",sln)

output

enter the first number 10

enter the second number 15

enter the third number20

enter the forth number 25

enter the first number 10

enter the second number 15

enter the third number 20

enter the forth number 25

second largest number= 25


Program No: 20

Aim: Find the sum of given number

Author: Varchasava yadav Roll No 32 Class XIC

N=int(input("enter the number"))

ND=0

while N>= 1:

d=d%10

ND=ND+1

N=int(N/10)

print("number N digit =,"ND)


Program No: 21

Aim: Check that given number is a palendrom number or not

Author: Varchasava yadav Roll No 32 Class XIC

import math

n=int(input("enter the number"))

d1=n%10

n=int(n/10)

d2=n%10

n=int(n/10)

d3=n%10

n=int(n/10)

d4=n%10

d5=int(n/10)

reverse=d1*math.pow(10,4)+d2*math.pow(10,3)+d3*math.pow(10,2)+d4*math.pow(10,1)+d5*mat
h.pow(10,0)

if (palendro == reverse ):

print ("palendro number")

else:

print ("not palendro number")


Program No: 22

Aim: Converting binary to decimal

Author: Varchasava yadav Roll No 32 Class XIC


dn=int(input("enter the number"))

bn=[ ]

i=0

while(dn>=1):

d=dn%2

bn.insert(i,d)

i+=1

dn=int(dn/2)

bn.reverse ()

print("binary number=",bn)

output

enter the number 12

binary number= [1, 1, 0, 0]


Program No:23

Aim: Find the sum and no of all coins

Author: Varchasava yadav Roll No 32 Class XIC


n1=eval(input("enter the first paisa"))

n2=eval(input("enter the second paisa"))

n3=eval(input("enter the third paisa"))

n4=eval(input("enter the forth rupee"))

n5=eval(input("enter the fifth rupee"))

n6=eval(input("enter the sixth rupee"))

n7=eval(input("enter the seventh rupee"))

n8=eval(input("enter the eighth rupee"))

n9=eval(input("enter the ninth rupee"))

n10=eval(input("enter the tenth rupee"))

n11=eval(input("enter the eleventh rupee"))

n12=eval(input("enter the twelvth rupee"))

n13=eval(input("enter the thirteenth rupee"))

n14=eval(input("enter the forteenth rupee"))

s=n1+n2+n3+n4+n5+n6+n7+n8+n9+n10+n11+n12+n13+n14

print("sum of all coins=",s)

output

enter the first paisa 5

enter the second paisa10

enter the third paisa20

enter the forth rupee50


enter the fifth rupee1

enter the sixth rupee2

enter the seventh rupee5

enter the eighth rupee10

enter the ninth rupee20

enter the tenth rupee50

enter the eleventh rupee100

enter the twelvth rupee200

enter the thirteenth rupee500

enter the forteenth rupee2000

sum of all coins= 2973


Program No: 24

Aim: Find the distance and speed of a train

Author: Varchasava yadav Roll No 32 Class XIC


=eval(input("enter the distance"))

s=eval(input("enter the speed"))

time=(d/s)

print("time taken",time)

output

enter the distance86

enter the speed86

time taken 1.0


Program No: 25

Aim: converting decimal to octal

Author: Varchasava yadav Roll No 32 Class XIC


dn=int(input("enter the number"))

on=[ ]

i=0

while (dn>=1):

d=dn%8

on.insert(i,d)

i=i+1

dn=int(dn/8)

on.reverse()

print("octal number=",on)

output

enter the number 500

octal number= [7, 6, 4]


Program No: 26

Aim: converting deimal to hexa decimal

Author: Varchasava yadav Roll No 32 Class XIC

dn=int(input("enter the number"))

hd= [ ]

i=0

while (dn>=1):

d=dn%16

if d<=9:

hd.insert(i,d)

elif d==10:

hd.insert (i,'a')

elif d==11:

hd.insert (i,'b')

elif d==12:

hd.insert (i,'c')

elif d==13:

hd.insert (i,'d')

elif d==14:

hd.insert (i,'e')

hd.reverse ()

print ("hexa decimal=",hd)


Program No: 27

Aim: Find the simple interest and compound interest

Author: Varchasava yadav Roll No 32 Class XIC


import math

p=eval(input("enter the principle"))

r=eval(input("enter the rate"))

t=eval(input("enter the time"))

si=(p*r*t)/100

amount=p+si

AC=p*math.pow((1+r/100),t)

ci=AC-p

print(si)

print(AC)

print(amount)

print(ci)

output

enter the principle3

enter the rate2

enter the time1

0.06

3.06

3.06

0.06000000000000005
Program No: 28

Aim: To find sum and reverse of a digit

Author: Varchasava yadav Roll No 32 Class XIC


#programme to find the sum and reverse of 5-digit

n=eval(input("enter the 5-digit number")

d1=n%10

n=int(n/10)

d2=n%10

n=int(n/10)

d3=n%10

n=int(n/10)

d4=n%10

d5=n

sum=d1+d2+d3+d4+d5

reverse=d1*10*10*10*10+d2*10*10*10+d3*10*10+d4*10+d5

print(sum)

print(reverse)
Program No: 30

Aim: Find the sum and average of five numbers

Author: Varchasava yadav Roll No 32 Class XIC

N1=eval(input("enter the first number;"))

N2=eval(input("enter the second number;"))

N3= eval(input("enter the third number;"))

N4=eval(input("enter the fourth number;"))

N5=eval(input("enter the fifth number;"))

sum=N1+N2+N3+N4+N5

average=N1+N2+N3+N4+N5/5

print("sum",sum)

print("average",average)

output

enter the first number;5

enter the second number;5

enter the third number;5

enter the fourth number;5

enter the fifth number;5

sum 25

average 21.0
Program No: 31

Aim: Find the area and semi-area of a triangle

Author: Varchasava yadav Roll No 32 Class XIC


import math

side1=eval(input("enter the firsts side"))

side2=eval(input("enter the second side"))

side3=eval(input("enter the third side"))

s=(side1+side2+side3)/2

a=math.sqrt(s*(s-side1)*(s-side2)*(s-side3))

print("semiperimeter=",s)

print("area=",a)

output

enter the firsts side10

enter the second side5

enter the third side10

semiperimeter= 12.5

area= 24.206145913796355
Program No:32

Aim: Find the area of a circle

Author: Varchasava yadav Roll No 32 Class XIC


r1=eval(input("enter the first radius"))

C = 2*3.14*r1

A = 3.14*r1*r1

print("circumference=",C)

print("area =",A)

output

enter the first radius34

circumference= 213.52

area = 3629.84
Program No: 33

Aim: Find the curved surface area,total surface area and volume of a
cylinder

Author: Varchasava yadav Roll No 32 Class XIC


=eval(input("enter the radius"))

h=eval(input("enter the height"))

csa=2*3.14*r*h

tsa=2*3.14*r*(h+r)

v=3.14*r*r*h

print("curved surface area=",csa)

print("total surface area=",tsa)

print("volume =",v)

output

enter the radius 5

enter the height 10

curved surface area= 314.0

total surface area= 471.00000000000006

volume = 785.0
Program No:34

Aim: check that three side are forming a triangle or not if they are forming
a triangle then which type of triangle it is

Author: Varchasava yadav Roll No 32 Class XIC


import math

s1=eval(input("enter the first side "))

s2=eval(input("enter the second side"))

s3=eval(input("enter the third side"))

if(s1+s2>s3)or(s2+s3>s1)or(s3+s1>s2):

print ("three side are forming the triangle")

if (s1==s2)and(s2==s3)and(s3==s1):

print ("equilateral triangle")

elif(s1==s2)or(s2==s3)or(s3==s1):

print("isoceleus triangle")

elif (s1!=s2)and (s2!=s3)and(s3!=s1):

print ("scalene triangle")

elif(math.pow(s1,2)+math.pow(s2,2)==math.pow(s3,2))or
(math.pow(s2,2)+math.pow(s3,2)==(s1,2))or(math.pow(s3,2)+math.pow(s1,2)==math.pow(s2,2)):

print ("right triangle")

sp=(s1+s2+s3)/2

a=main.sqrt(sp*(sp-s1)*(sp-s2)*(sp-s3))

print(sp)

print(a)

else: print (" the number not forming a triangle")

output

enter the first side 2

enter the second side 2


enter the third side 2

three side are forming the triangle

equilateral triangle
Program No: 35

Aim: Numerical literal

Author: Varchasava yadav Roll No 32 Class XIC


a=0b1010

b=100#decimal literal

c=0o310#octal literal

d=0x12c#hexadecimal literal

#float literal

float_1=10.5

float_2=1.5e2

#complex literal

x=3.14j

print(a,b,c,d)

print(float_1,float_2)

print(x,x.imag,x.real)

output

10 100 200 300

10.5 150.0

3.14j 3.14 0.0


Program No: 37

Aim: Converting decimal to octal

Author: Varchasava yadav Roll No 32 Class XIC


dn=int(input("enter the number"))

on=[ ]

i=0

while (dn>=1):

d=dn%8

on.insert(i,d)

i=i+1

dn=int(dn/8)

on.reverse()

print("octal number=",on)

output

enter the number 500

octal number= [7, 6, 4]


Program No: 38

Aim: Find the sum of first odd natural no

Author: Varchasava yadav Roll No 32 Class XIC


n=eval(input("enter the n number"))

i=1

sum=0

while(i<=n):

sum=sum+i

i+=2

print("sum of first odd number=",sum)

output

enter the n number 5

sum of first odd number= 9


Program No: 39

Aim: Find the sum of first even natural no

Author: Varchasava yadav Roll No 32 Class XIC


N=int(input("Enter the number"))

sum1=0

sum2=0

for i in range(1,N+1,2):

sum1=sum1+i

print("sum of n odd natural number =",sum1)

for i in range (0,N+1,2):

sum2=sum2+i

print("sum of even natural number =",sum2)

output

Enter the number5

sum of n odd natural number = 9

sum of even natural number = 6

Program No: 40

Aim: Find the age of a person

Author: Varchasava yadav Roll No 32 Class XIC


cy=eval(input("enter the current year"))

cm=eval(input("enter the current month"))

cd=eval(input("enter the current day"))

by=eval(input("enter the birth year"))

bm=eval(input("enter the birth month"))

bd=eval(input("enter the birth date"))

if(cd<bd):
if(cm==1)or(cm==3):

cd=cd+31

cm=cm-1

elif(cm==4)or(cm==6):

cd=cd+30

cm=cm-1

if(cy%4==0):

cd=cd+29

cm=cm-1

else:cd=cd+28

cm=cm-1

if(cm<bm):

cm=cm+12

cy=cy-1

nd=cd-bd

nm=cm-bm

ny=cy-by

print("you are=",ny,nm,nd,sep=('_'))

output

enter the current year2018

enter the current month9

enter the current day17

enter the birth year2001


enter the birth month6

enter the birth date20

you are=_17_3_-3

You might also like