Page 183 - Computer Science Class 11 With Functions
P. 183
(-5, 4)
Notenthatnwhennonenofnthendividendnandndivioornionpooitvenandnthenothernionnegatve,nthenquotentnionnegatvenandn
thenvaluenofnthenremaindernionadjuotednoonthatnthenoignnofnthenremaindernmatcheonthenoignnofnthendivioor,nfornexample,n
-21 = 5×(-5) + 4. Similarly,
>>> divmod(21, -5)
(-5, -4)
Aonbefore,ninnthenabovenexample,nwennotenthatn21 = -5×(-5) + (-4).
>>> divmod(-21, -5)
(4, -1)
Notenthatnwhenneachnofnthendividendnandndivioornionnegatve,nthenquotentnionpooitve.nAgain,nthenvaluenofnthenremaindern
ionadjuotednoonthatnthenoignnofnthenremaindernmatcheonthenoignnofnthendivioor,nfornexample.n-21 = -5 × 4 + (-1).
abs()
Thenabs()nfunctonnreturnonaboolutenvaluenofninteger,nfloatng-point,norncomplexnnumbernprovidednaonthenargument.
orninotance,nthenfollowingnfunctonncallonreturnnthenaboolutenvalueonofn-12, -14.7,n21,nand 4 + 3j.
>>> abs(-12)
12
>>> abs(-14.7)
14.7
>>> abs(21)
21
>>> abs(4 + 3j)
5.0
pow()
Thenpow()nfunctonnntakeontwon(ornmorennumericnvalueo),noaynnum1,nnum2,nandnnum3n(optonal)naonanninputnfromnthen
uoernandnnreturnonnum1 raioedntonthenpowernof num2. Optonalninput, num3, whennprovided,nionuoedntoncomputen
thenremaindernobtainednonndividingnnum1 num2 by num3, i.e.ntoncompute num1 num2 %num3. orninotance,nthen
3
5
4
followingnfunctonncalloncomputenthenvalueonofn14 , 3 %5, and -2.3 .
>>> pow(14, 3)
2744
>>> pow(3, 4, 5)
1
>>> pow(-2.3, 5)
-64.36342999999998
round()
Thenround()nfunctonntakeontwonnumericnvalueo,nnamely,nnumnandndigitnaonargumentonfromnthenuoernandnroundonoffn
thengivenninputnnumbernnumntonthenneareotnintegernornupntonthenopecifiednprecioionn(digits)nafternthendecimalnpoint.n
orninotance,nthenfollowingnfunctonncallonroundonthenvalueon10.6ntonneareotninteger 11,n13.8907ntonneareotnintegern
13.89nuptontwondecimalnplaceo, -12.0456nton-12.046nuptonthreendecimalnplaceo,nandn-12.96nton-13.n
>>> round(10.6)
11
>>> round(13.8907, 2)
13.89
>>> round(-12.0456, 3)
-12.046
>>> round(-12.96)
-13
The round(number, ndigits) rounds off the specified number to the number of digits specified as the
second argument ndigits. If the second argument is not specified. Number is rounded to the nearest integer.
Introductonnton unctono 181

