Experiment 1
Experiment 1
MENT1
AI
M:Pr
ogr
am t
odemons
trat
ePyt
honoper
ator
s,dat
atypes
,andcont
rol
stat
ement
s
1
.Dat
aTypesandAr
it
hmet
icOper
ator
s
CODE:
x=1
0 #i
ntegerdat
atype
y=3.
5 #f
loatdat
atype
name="
Pyt
hon"#s
tri
ngdat
atype
#Per
for
mingar
it
hmet
icoper
ati
ons
s
um_
res
ult=x+y
di
ff
erence=x-y
pr
oduct=x*y
di
vi
si
on=x/y
modul
us=x%y
#Di
spl
ayi
ngr
esul
ts
pr
int
(f
"Sum:
{sum_
res
ult
}"
)
pr
int
(f
"Di
ff
erence:
{di
ff
erence}
")
pr
int
(f
"Pr
oduct
:{pr
oduct
}"
)
pr
int
(f
"Di
vi
si
on:
{di
vi
si
on}
")
pr
int
(f
"Modul
us:
{modul
us}
\n"
)
OUTPUT:
Sum:1
3.5
Di
ff
erence:
6.5
Pr
oduct
:35.
0
Di
vi
si
on:
2.8571
428571
42857
Modul
us:
3.0
2.
Rel
ati
onal
Oper
ator
sandCondi
ti
onal
Stat
ement
s
I
nputt
wonumber
s
num1=i
nt(
input
("
Ent
ert
hef
ir
stnumber
:")
)
num2=i
nt(
input
("
Ent
ert
hes
econdnumber
:")
)
#Rel
ati
onal
oper
ator
stocompar
ethenumber
s
i
fnum1>num2:
pr
int
(f
"{
num1
}isgr
eat
ert
han{
num2}
")
el
i
fnum1<num2:
pr
int
(f
"{
num1
}isl
esst
han{
num2}
")
el
se:
pr
int
(f
"{
num1
}isequal
to{
num2}
")
OUTPUT:(wr
it
etheout
putyougetaf
terent
eri
ngt
henumber
s)
3.
Progr
am t
ocal
cul
atet
hef
act
ori
alofanumberus
ingawhi
l
eloop
#I
nputanumber
num =i
nt(
input
("
Ent
erapos
iti
vei
nteger
:")
)
#I
nit
ial
i
zef
act
ori
alvar
iabl
e
f
act
ori
al=1
i
=num
#Us
ingwhi
l
eloopt
ocal
cul
atef
act
ori
al
whi
l
ei>0:
f
act
ori
al*=i
i
-=1#Decr
eas
eiby1i
neachi
ter
ati
on
#Di
spl
ayt
her
esul
t
pr
int
(f
"Thef
act
ori
alof{
num}i
s:{
fact
ori
al}
")
OUTPUT:(Wr
it
edownt
heout
putyougetaf
terent
eri
ngt
henumber
)
4.
Progr
am t
odemons
trat
eas
signmentoper
ator
s
#I
nit
ial
i
zingavar
iabl
e
num =1
0
pr
int
(f
"I
nit
ial
val
ueofnum:
{num}
")
#Us
ing+=oper
ator
pr
int
(f
"Af
ter+=5,
num i
s:{
num}
")
#Us
ing-
=oper
ator
num -
=3 #equi
val
entt
onum =num -3
pr
int
(f
"Af
ter-
=3,
num i
s:{
num}
")
#Us
ing*=oper
ator
num *=2#equi
val
entt
onum =num *2
pr
int
(f
"Af
ter*=2,
num i
s:{
num}
")
#Us
ing/
=oper
ator
num /
=4 #equi
val
entt
onum =num /4
pr
int
(f
"Af
ter/
=4,
num i
s:{
num}
")
#Us
ing%=oper
ator
pr
int
(f
"Af
ter%=3,
num i
s:{
num}
")
#Us
ing**=oper
ator
num =5
num **=2#equi
val
entt
onum =num **2
pr
int
(f
"Af
ter**=2,
num i
s:{
num}
")
#Us
ing/
/=oper
ator
num /
/=3 #equi
val
entt
onum =num /
/3
pr
int
(f
"Af
ter/
/=3,
num i
s:{
num}
")
OUTPUT:(YOUCANCHANGEI
NITI
ALVALUEI
FYOUWANT)
I
nit
ial
val
ueofnum:1
0
Af
ter+=5,
num i
s:1
5
Af
ter-
=3,
num i
s:1
2
Af
ter*=2,
num i
s:24
Af
ter/
=4,
num i
s:6.
0
Af
ter%=3,
num i
s:0.
0
Af
ter**=2,
num i
s:25
Af
ter/
/=3,
num i
s:8