0% found this document useful (0 votes)
1 views2 pages

python unit-3

Uploaded by

Hemanth Kumar1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views2 pages

python unit-3

Uploaded by

Hemanth Kumar1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
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

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy