Professional Documents
Culture Documents
Take three suitable examples for Sr. No. 1 to 19 and write corresponding output
below it.
>>> print(abs(7))
Output: 7
>>>
Output
3
>>>
import math
print(math.ceil(-5.4))
Output
-5
>>>
Output
-6
>>>
Import math
Print(math.floor(11.3))
Output
11
4. log(x) The natural logarithm of x, for x> 0
import math
print(math.log(2))
0.6931471805599453
>>>
import math
print(math.log(4))
1.3862943611198906
>>>
Import math
print(math.log(10))
2.302585092994046
>>>
5. log10(x) The base-10 logarithm of x for x> 0.
import math
print(math.log10(10))
1.0
>>>
import math
print(math.log10(100))
2.0
>>>
Import math
Print(math.log10(1000))
3.0
>>>
6. max(x1, x2,...) The largest of its arguments:
max(5,6,7,8,0)
8
>>> max(1,2,3,4)
4
>>> max(5,6,7,8)
8
>>> max(2,3,5,8)
8
>>>
11. Random()
import random
>>> random.random()
0.22726385865134568
>>> random.random()
0.47022612121603313
>>> random.random()
0.8462540060772397
>>> random.random()
0.6273887977069514
>>>
12. math.factorial(x)
Return x factorial as an integer. Raises ValueError if x is not integral or is
negative.
>>> math.factorial(3)
>>> math.factorial(6)
720
>>> math.factorial(5)
120
>>>
13. math.gcd(*integers)
Return the greatest common divisor of the specified integer arguments. If any of
the arguments is nonzero, then the returned value is the largest positive integer
that is a divisor of all arguments. If all arguments are zero, then the returned
value is 0. gcd() without arguments returns 0.
>>> math.gcd(9,3)
>>> math.gcd(15,27)
>>> math.gcd(35,70)
35
>>>
14. math.exp(x) Return e raised to the power x, where e = 2.718281… is the
base of natural logarithms
>>> math.exp(2)
7.38905609893065
>>> math.exp(3)
20.085536923187668
>>> math.exp(-2)
0.1353352832366127
>>>.
>>> math.cos(30)
0.15425144988758405
>>> math.cos(0)
1.0
>>> math.cos(1)
0.5403023058681398
>>>
>>> math.sin(3.14)
0.0015926529164868282
>>> math.sin(60)
-0.3048106211022167
>>> math.sin(30)
-0.9880316240928618
>>> math.sin(3.14/2)
0.9999996829318346
>>>
>>> math.tan(3.14/3)
1.72992922008979
>>> math.tan(3.14/2)
1255.7655915007897
>>> math.tan(3.14/6)
0.576996400392873
>>>
Angular conversion
Math Constants
math.pi The mathematical constant π = 3.141592…, to available precision.
math.e The mathematical constant e = 2.718281…, to available precision.
Number Representations:
Perform following operations of numbers.
Declare and print three variables of each number systems (Decimal, Binary, Octal and Hexadecimal
numbers).
1. Convert any three decimal numbers into the binary number system
o N1 = 4
o N1 in Binary = 100
o >>>bin(2)
o '0b10'
o >>> bin(3)
o '0b11'
o >>> bin(4)
o '0b100'
o >>>
2. Convert any three decimal numbers into the octal number system
o >>> oct(2)
o '0o2'
o >>> oct(10)
o '0o12'
o >>> oct(6)
o '0o6'
o >>>
3. Convert any three decimal numbers into the hexadecimal number system
>>> hex(34)
'0x22'
>>> hex(390)
'0x186'
>>> hex(53463878)
'0x32fcb46'
>>>
o
4. Convert following binary number into hexadecimal. 11011011110101
>>> hex(0b11011011110101)
'0x36f5'
o
5. Convert following hexadecimal number into binary. ABC
o >>> bin(0xABC)
o '0b101010111100'
o >>
6. Convert following octal number into binary. 543
o >>> bin(0o543)
o '0b101100011'
o
#Binary Representations
n3 = 0b101
print(n3)
#Octal representations
n6=0o51
print(n6)
#Hexa-decimal representations
n7 = 0xA
print(n7)