Importing#
import math # use as math.sqrt(16)
from random import randint # use as randint(1, 6)
import statistics as st # alias
math module#
| Function | Example |
|---|---|
| math.sqrt(x) | sqrt(25) → 5.0 |
| math.pow(x, y) | pow(2, 3) → 8.0 |
| math.ceil(x), math.floor(x) | ceil(4.2) → 5, floor(4.8) → 4 |
| math.fabs(x) | absolute value as float |
| math.factorial(n) | factorial(5) → 120 |
| math.gcd(a, b) | gcd(12, 18) → 6 |
| math.pi, math.e | constants |
| math.sin(x), cos, tan | x in radians |
random module#
random.random() → float in [0, 1); random.randint(a, b) → integer a ≤ n ≤ b (both included); random.randrange(start, stop, step) (stop excluded); random.choice(seq); random.shuffle(list).
statistics module#
mean(), median(), mode().
मॉड्यूल तैयार फ़ंक्शनों का संग्रह है जिसे import से उपयोग करते हैं। math में sqrt, ceil, floor, factorial; random में randint (दोनों सीमाएँ शामिल) और randrange (अंतिम सीमा शामिल नहीं); statistics में mean, median और mode मिलते हैं।
Exam tips#
- Possible outputs of random-based code: list which values randint/randrange can produce.