Untitled Document
Untitled Document
1. math.sqrt(x)
○ Description: Returns the square root of x.
○ Syntax: math.sqrt(x)
○ Return Value: Float, the square root of x.
○ Example: math.sqrt(16) returns 4.0.
2. math.pow(x, y)
○ Description: Returns x raised to the power y (x^y).
○ Syntax: math.pow(x, y)
○ Return Value: Float, the value of x raised to y.
○ Example: math.pow(2, 3) returns 8.0.
3. math.floor(x)
○ Description: Returns the largest integer less than or equal to x.
○ Syntax: math.floor(x)
○ Return Value: Integer.
○ Example: math.floor(3.7) returns 3.
4. math.ceil(x)
○ Description: Returns the smallest integer greater than or equal to x.
○ Syntax: math.ceil(x)
○ Return Value: Integer.
○ Example: math.ceil(3.2) returns 4.
5. math.factorial(x)
○ Description: Returns the factorial of x.
○ Syntax: math.factorial(x)
○ Return Value: Integer.
○ Example: math.factorial(5) returns 120.
random Module:
1. random.random()
○ Description: Returns a random floating-point number between 0.0 and 1.0.
○ Syntax: random.random()
○ Return Value: Float.
○ Example: random.random() might return 0.5678.
2. random.randint(a, b)
○ Description: Returns a random integer between a and b (inclusive).
○ Syntax: random.randint(a, b)
○ Return Value: Integer.
○ Example: random.randint(1, 10) might return 7.
○
3. Random.randrange - same arguments as range excludes end includes start. (start, stop , step)
4. random.choice(seq)
○ Description: Returns a random element from the non-empty sequence seq.
○ Syntax: random.choice(seq)
○ Return Value: Element from the sequence.
○ Example: random.choice([1, 2, 3, 4]) might return 3.
5. random.shuffle(seq)
○ Description: Shuffles the elements of the list seq in place.
○ Syntax: random.shuffle(seq)
○ Return Value: None (modifies the list in place).
○ Example: If seq = [1, 2, 3, 4], random.shuffle(seq) might rearrange it to
[3, 1, 4, 2].
6. random.uniform(a, b)
○ Description: Returns a random floating-point number between a and b.
○ Syntax: random.uniform(a, b)
○ Return Value: Float.
○ Example: random.uniform(1, 10) might return 5.672.
statistics Module:
1. statistics.mean(data)
○ Description: Returns the mean (average) of the numeric data.
○ Syntax: statistics.mean(data)
○ Return Value: Float.
○ Example: statistics.mean([1, 2, 3, 4]) returns 2.5.
2. statistics.median(data)
○ Description: Returns the median (middle value) of the numeric data.
○ Syntax: statistics.median(data)
○ Return Value: Float or int.
○ Example: statistics.median([1, 2, 3, 4, 5]) returns 3.
3. statistics.mode(data)
○ Description: Returns the most common data point (mode).
○ Syntax: statistics.mode(data)
○ Return Value: Single value (most frequent).
○ Example: statistics.mode([1, 2, 2, 3, 4]) returns 2