clASSMAte
Date
Page
BASIC PYTHON PROGIRAMS
Puthon Program to print q11_prime number in
iven intexval
Code eTuL KomeklLNKEpIal)
NOTES GmERY (TELEGRF)
Staxt I_
end =75
Print (prime numb ess between Shart and
end are:")_
Foxiin yange stast,end t
fox in ange (2,i) :
break
else
pxint L )
Output
Prime numbexs between il and 25 are
13 17 1923 293 37 43
43 59 61 6 1 13
Pth on_progyame t0 print Squase of aiven
Dumbez
Lode
num =int (input enteY numbeY: "))
Squaye = n*n
print Sguare is Square)
Output:
entey numbe lo
SquaYe is 100
classMAte
Date
Page
Python_proqyam to _print table of given number:
Code
DEint Linput entey the numbey to priot fable_
fox 2
foriin yange L u ) :
print (i *n_)_
Output enter numbex to print table foY 1
R8 TUL COmRLNKCOIN).
35 NOTES CRUERY CTELEGRAM).
42
4
56
63
10
4 Puthon Poaram to add two numbexS
Code
numi 20
num 2= 175
Sum= num t num 2
print (me sum oe {O and {)_is {3}
forma (numl, num 2 Sum)
Output
he sum of a0 and 1a.5 is 33 5
sSMALe.
Date
Page
b ython pr0gxem to print calandex
Code:
impoxting Calgndey module
impoxE calander
yy 2022 tyea
mm tmonth
MU Kmm LuNKEDIN).
aloTES qMLERY CTELEGRPm).
displaying calandeY
pxint calandex Month (yumml)
Qutput
NOV 20R2
Mon Tue lWled_ Thu Fi Sat Sun.
3 5 6
13 13
15 16 12 18 19
2 23 24 25 26
8 30
6 Putmon_px0gxam to_Swap two numbers:
Code
XE5
Swapping of numbey using thixd variable
femp
X_
y temp
print( yalue ofx after Swapplnq:0fovmat (X))|
print Cvalue bf y aftey Soaping:{:fovmat (y))
Output:
Value oFx a ftey Sw9ppin9 10
value of y a Fter Swapplng: 5
3
ASSMALe
Date
Page
Puthon pro@yam to find factoyigi of_numbey
Code:
hum = uL IWmAR LLNKGDIN)
a c t =I NoTes GMLERY (TELEGLAT).
fox i in xange (L, num +|):
fact =Fact iL
prlnt factorial is : foymat Cfact ))
Output
Factoxial is 5040
8 Puthon_p1oq1am to Conveyt decimal to QtheY
numbey Sustem..
Code
dec =344
print (he decimgi value ofdec is
pint (bin (dec) i n binayu.")_
pxint(Oct Cdec )" in octal ")_
print(hex (dec) i n hexadecimal.")_
Output
The decimal value of 344is
obl010UO06 in binQyu
OOS30 in Octai
0x1S8in hexad ecîmal
9 uthon pr0gxem to_print a * pattexn
Code
Dws=int linputentex numbex of vowS:")
fori in range(zons )):
fori in xange (i+)E " "
Pxint * " end
print \n ")
clASSMAte.
Date
Page
Python ProqYam to find LCM
code
def compute lcm X,
if x>
y
Qreatey = x_
elke: MUL UomeRlUNKEpIN).
NOTES qLERY LTELEGLArM)
Gyearey u
While Tue )::
IA(Greater/: x==0)andlareater 1u=0)):
c m= Qyeatex
bye ak
xetuxn LCM
num 5 4
num 2 24
priot h e Lc.M. is Compute-1c mlnum1.num 2
Puthon_ pxogyam to add tw0 matyices
Code:
x = C12, 3 1
456
LI 8 L
Ls 8, ,
C6 31,.
LI 5,
tor i in yange (len (X))
Fox in xange (len ly)):
xesuit CitJ] =xCill) +y Cil[s).
for y n yesult:
print (Y ):
clASSMAte
Date
Page
Output:
( 5, 4))
Cto 12,
L 13 18J
1 ython_pyogyam to find Sum QYYQ
C.ode
defSum(ayr)
Sum=O_ PUL KomaR CUNKEDIn).
ANOTEs qLERY CTeLEG RAM).
fox i in arY:
Sum= SUmti
Yetuxn (sum)
Qxy-1
axy =L12,3,4 1S1
n len ayy )
ans -Sum(ayT)
pzint Sum of the axray isans)
Output
Sum of ARRAy is 24
13 Puthon Program to Find aeq Of CYcle
Code
Code:
def findavea Y):
PI - 3.142
etuxn PI* (Y* ) :
prlnt ("AREA iS . 6F " findareg (S2):