Program No:1 Aim: Find The Sum of N Natural Numbers Author: Varchasava Yadav Roll No 32 Class XIC
Program No:1 Aim: Find The Sum of N Natural Numbers Author: Varchasava Yadav Roll No 32 Class XIC
Program No:1 Aim: Find The Sum of N Natural Numbers Author: Varchasava Yadav Roll No 32 Class XIC
i=1
sum=0
while(i<=n):
sum=sum+i
i+=1
output
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
print(modull.pi)
print (modull.gravity)
output
3.14
9.8
Program No: 4
Aim: Keywords
import keyword
output
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
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
sum=n1+n2+n3+n4+n5
avg=sum/5
output
Aim: module
gravity=9.8
OUTPUT
[evaluate modull.py]
Program No:8
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.5 150.0
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.
import math
if(s1+s2>s3)or(s2+s3>s1)or(s3+s1>s2):
if (s1==s2)and(s2==s3)and(s3==s1):
elif(s1==s2)or(s2==s3)or(s3==s1):
print("isoceleus 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)):
sp=(s1+s2+s3)/2
a=main.sqrt(sp*(sp-s1)*(sp-s2)*(sp-s3))
print(sp)
print(a)
output
equilateral triangle
Program No:10
i=1
sum=0
while(i<=n):
sum=sum+i
i+=1
output
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
you are=_17_3_-3
Program No: 12
sum=0
for i in range(1,n+1):
sum=sum+i
output
if (year % 4==0):
else:
output
i=1
sum=0
while(i<=n):
sum=sum+i
i+=2
output
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
if sp==cp:
elif sp>cp:
print("profit")
profit=sp-cp
profitpercentage=(profit/cp)*100
print("profit=",profit)
else:
print("loss")
loss= cp-sp
losspercentage=(loss/cp)*100
print("loss")
output
no profit no loss
Program No: 17
sum1=0
sum2=0
for i in range(1,N+1,2):
sum1=sum1+i
sum2=sum2+i
output
ln=a
if b>ln:
ln=b
elif c>ln:
ln=c
else:
ln=d
print("largest number=",ln)
sln=a
if b<sln:
sln=b
elif c<sln:
sln=c
else:
sln=d
print("second largest number=",sln)
output
ND=0
while N>= 1:
d=d%10
ND=ND+1
N=int(N/10)
import math
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 ):
else:
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
s=n1+n2+n3+n4+n5+n6+n7+n8+n9+n10+n11+n12+n13+n14
output
time=(d/s)
print("time taken",time)
output
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
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 ()
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
0.06
3.06
3.06
0.06000000000000005
Program No: 28
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
sum=N1+N2+N3+N4+N5
average=N1+N2+N3+N4+N5/5
print("sum",sum)
print("average",average)
output
sum 25
average 21.0
Program No: 31
s=(side1+side2+side3)/2
a=math.sqrt(s*(s-side1)*(s-side2)*(s-side3))
print("semiperimeter=",s)
print("area=",a)
output
semiperimeter= 12.5
area= 24.206145913796355
Program No:32
C = 2*3.14*r1
A = 3.14*r1*r1
print("circumference=",C)
print("area =",A)
output
circumference= 213.52
area = 3629.84
Program No: 33
Aim: Find the curved surface area,total surface area and volume of a
cylinder
csa=2*3.14*r*h
tsa=2*3.14*r*(h+r)
v=3.14*r*r*h
print("volume =",v)
output
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
if(s1+s2>s3)or(s2+s3>s1)or(s3+s1>s2):
if (s1==s2)and(s2==s3)and(s3==s1):
elif(s1==s2)or(s2==s3)or(s3==s1):
print("isoceleus 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)):
sp=(s1+s2+s3)/2
a=main.sqrt(sp*(sp-s1)*(sp-s2)*(sp-s3))
print(sp)
print(a)
output
equilateral triangle
Program No: 35
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.5 150.0
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
i=1
sum=0
while(i<=n):
sum=sum+i
i+=2
output
sum1=0
sum2=0
for i in range(1,N+1,2):
sum1=sum1+i
sum2=sum2+i
output
Program No: 40
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
you are=_17_3_-3