0% found this document useful (0 votes)
1 views

python unit-3

Uploaded by

Hemanth Kumar1
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views

python unit-3

Uploaded by

Hemanth Kumar1
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Random Functions

randint
§ Generates a random integer
§ Randint accepts two parameters: a lowest and a highest
number.
Example
import random # generates a number between 1 to 5
random.randint(1,5)
choice
§ Generates a random value from the sequence.
Example
random. choice( ['red', 'black', 'green'] )
>>> 'green'
shuffle
The shuffle function, shuffles the elements in list in place, so
they are in a random order.
Example
l1=[i for i in range(10)]
print(l1)
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
random. shuffle(l)
print(l1)
[7, 6, 9, 0, 5, 2, 4, 1, 8, 3]
___________________________________
The math module is a standard module in Python and is always
available. To use mathematical functions under this module, you
have to import the module using import math.

Functions in math module


Function Description
ceil(x) Returns the smallest integer greater than or equal to x.
floor(x) Returns the largest integer less than or equal to x
copysign(x, y) Returns a float value of x with the sign of y
fabs(x) Returns the float absolute value of x
factorial(x) Returns the factorial of x
exp(x) Returns e**x
pow(x, y) Returns x raised to the power y
sqrt(x) Returns the square root of x

You might also like