Python 2
Python 2
Stuings
Code :
priat('23'" , 'use") Output!
123456
" In Python text ins ide
zuotes i's treated as a sting,
The 4' opeY atos wtn st ing s Cona
tena tes
adding them. Jet the Su m 59
them, ins tecd af
wee
with iateg ers, not strings need to Ork
IntegerS
An inte gey is ba sic data
a
numbe'
type YepYesen ting oh ole
from
negative to posibe
strings, which handle tex t, inclding teio Ualike
integ ers are Crafted for
numerc oper atio ns such as
addibon, subtrac tion mu itiplica tiog,
si on and
divi 5i0n and mnore
"With guotes ' (oncatenates ond ithout guote s adds.
data-tYpe
tyee
to reve al the
" print data- type
Code Outpu t
Lcla ss int'>
1 t Days in a week
days.in_ week :1
3
4. Get data type
S data- type ty pe (days. in- wee k)
6
upe()
Type Convessibn
<classint'>
enter number: 23
plea se
<closs 34y'
to floa t
i) Sthing
Code
dema number from the useT.
decimat number)
2. userinpu t inpu t (please entex a
4# onvert to floa t
Rules of ConvexsI0 n
st (23) 123
st (23 s) l23-5a
sts (rue) "Tyue
Str (False) "False
Con vevsion
bool () Type
bool() funeton trans fos ms a value into a booleon,
The
fevcentage Caleulation
100/.
A $ 200 gadget i th a L0 dis tount touw much i S
saved
AnS To fnd o/. o 200 si mpy divide 1o by
1D0. and then
mu lt'ply this by 200, lke this:
Code
Outpub.
pvint (1o/1D0 * 200) 20"0
Solving Tules
" Py thon also folloues BoDMAS tyfe Tule (PEMDA)
Parentheses () broto
)
E M D A
Floos divisi'on
/3 = 3
Code : Output
print(n13) 366666
prnt(u))3) elk 3
" Normal aivision gives
flogt as output
"Floor division gives
intege as outpu t
"int( function is another method to obta In t.
ohole numbey a Pter divi's'on.5peciically it onverte
de ci mal number to integ ev s by emoving de cimal,
Code : Output
umber =L/s
2 priat(numbe)
3 pviat(int (numbe)
Tbund() Function
In
Python,if you want to Yound numbeS
can se the round() functibn
For deinals below os, 1'llround douwn
" for decima's ike oS or hig he, it' Yound up
Code:
1 RDunding 3-d
2: print (Yound (3 ) o'teiv/ 3
4.# Rounding 3
S print(round (3))
4Rounding 36
8' pvint (Yound(-6))
Python f - strings
Ty peErvot tn Blling
19kile butlding a silllng system, you entoun
tered a
TypErroí hen trying to display the totaf bilh using
the follong code
Code:
1 tal: iso
Solution 1:
To fix it, convet to tal to
a String using sttta)
before Concatenation
Co de
print ("Yous totol bill is: "+ str (tota))
Solution 2:
Le t's leavn a bettet method to combine di
ffere nt
data ty pes without u sing conver sion me thod s
like.
str()
f-stingsns2h9re lerit
|Rraject -2
E- Comnmes ce Product Price Calculator :