11-11_python[1]
11-11_python[1]
sqrt:
output:
4.0p
ceil(x): This function will round the value to the integer greater than or equal to x
value.
ceil(10.5)
ceil(4.6)
ceil(4)
output:
11
output:
D:\>py program1.py
11
floor(x): This function will round the value to the integer less than or equal to x
value.
floor(10.5)
floor(5)
output:
0.0
abs-->absolute
This function will give output without negative symbol.
output:
12.0
pi=3.141592653589793
D:\>py program1.py
enter the radius of a circle:4
Area of the circle is: 50.26548245743669
Random Module:
1.random()
2.uniform()
3.randint()
4.randrange()
5.choice()
1.random()
random() is used to generate random float values between 0 and 1(not inclusive)
0<x<1
output:
D:\>py program1.py
0.13764545877139434
D:\>py program1.py
0.6645396333772283
D:\>py program1.py
0.317592306214567
D:\>py program1.py
0.06021067330547558
D:\>py program1.py
0.55280180355482
output:
D:\>py program1.py
0.6195619383673585
0.7650319773672067
0.5412240104114934
0.266770039235096
0.0333846858571627
0.6890254563976113
0.8336981460872318
0.2985762567369882
0.9394901124501817
0.45281382735622444
2.uniform()
syntax:
uniform(begin,end)
This function generates random float values between begin and end
output:
D:\>py program1.py
5.5272825265391345
D:\>py program1.py
6.768569412098124
D:\>py program1.py
4.32691156112012
output:
D:\>py program1.py
3.144048624311151
3.664401110815753
3.25814828067614
3.7498779679331617
3.940810141652418
3.randint()
randint(begin,end)
output:
D:\>py program1.py
9
D:\>py program1.py
8
D:\>py program1.py
2
D:\>py program1.py
Python 22 batch 7 pm Page 5
D:\>py program1.py
9
D:\>py program1.py
5
D:\>py program1.py
10
4.randrange()
randrange(begin,end,step)
*begin value is optional , if begin value is not given then default value is 0.
*step value is optional, if not given then default value is 1
begin value-->0
step value-->1
output:
D:\>py program1.py
1
D:\>py program1.py
1
D:\>py program1.py
4
D:\>py program1.py
2
D:\>py program1.py
4
D:\>py program1.py
4
D:\>py program1.py
2
[1,3,5,7,9]
D:\>py program1.py
1
D:\>py program1.py
1
D:\>py program1.py
1
D:\>py program1.py
7
choice():
syntax:
choice(list/tuple/string)
output:
D:\>py program1.py
grapes
D:\>py program1.py
apple
D:\>py program1.py
apple
D:\>py program1.py
banana
output:
D:\>py program1.py
apple
D:\>py program1.py
grapes
D:\>py program1.py
orange
output:
D:\>py program1.py
p
D:\>py program1.py
l
Python 22 batch 7 pm Page 8
l
D:\>py program1.py
p
D:\>py program1.py
a
D:\>py program1.py
a