import math
import math
print(dir(math))
['__doc__', '__loader__', '__name__', '__package__', '__spec__', 'acos', 'acosh', 'asin', 'asinh', 'atan', 'atan2', 'atanh', 'cbrt', 'ceil', 'comb', 'copysign', 'cos', 'cosh', 'degrees', 'dist', 'e', 'erf', 'erfc', 'exp', 'exp2', 'expm1', 'fabs', 'factorial', 'floor', 'fmod', 'frexp', 'fsum', 'gamma', 'gcd', 'hypot', 'inf', 'isclose', 'isfinite', 'isinf', 'isnan', 'isqrt', 'lcm', 'ldexp', 'lgamma', 'log', 'log10', 'log1p', 'log2', 'modf', 'nan', 'nextafter', 'perm', 'pi', 'pow', 'prod', 'radians', 'remainder', 'sin', 'sinh', 'sqrt', 'tan', 'tanh', 'tau', 'trunc', 'ulp']
print("Number Functions")
print("math.ceil(4.3) =", math.ceil(4.3)) # Smallest integer ≥ value
print("math.floor(4.7) =", math.floor(4.7)) # Largest integer ≤ value
print("math.trunc(5.9) =", math.trunc(5.9)) # Truncates decimal part
print("math.fabs(-7.5) =", math.fabs(-7.5)) # Absolute value
print("math.factorial(5) =", math.factorial(5)) # 5! = 120
print("math.modf(5.75) =", math.modf(5.75)) # (fractional, integer) parts
print("math.copysign(3, -8) =", math.copysign(3, -8)) # Copy sign of second value to first
print("math.isfinite(10) =", math.isfinite(10)) # True if finite
print("math.isinf(math.inf) =", math.isinf(math.inf)) # True for infinity
print("math.isnan(math.nan) =", math.isnan(math.nan)) # True for NaN
Number Functions math.ceil(4.3) = 5 math.floor(4.7) = 4 math.trunc(5.9) = 5 math.fabs(-7.5) = 7.5 math.factorial(5) = 120 math.modf(5.75) = (0.75, 5.0) math.copysign(3, -8) = -3.0 math.isfinite(10) = True math.isinf(math.inf) = True math.isnan(math.nan) = True
print("Power, Root, Exponential, Log Functions")
print("math.pow(2, 3) =", math.pow(2, 3)) # 2^3 = 8.0
print("math.sqrt(16) =", math.sqrt(16)) # Square root
print("math.exp(1) =", math.exp(1)) # e^1
print("math.expm1(1) =", math.expm1(1)) # e^1 - 1
print("math.log(8, 2) =", math.log(8, 2)) # Log base 2
print("math.log2(16) =", math.log2(16)) # Log base 2
print("math.log10(1000) =", math.log10(1000)) # Log base 10
print("math.log1p(1) =", math.log1p(1)) # log(1+x) accurate for small x
Power, Root, Exponential, Log Functions math.pow(2, 3) = 8.0 math.sqrt(16) = 4.0 math.exp(1) = 2.718281828459045 math.expm1(1) = 1.718281828459045 math.log(8, 2) = 3.0 math.log2(16) = 4.0 math.log10(1000) = 3.0 math.log1p(1) = 0.6931471805599453
print("Combinatorics")
print("math.comb(5, 2) =", math.comb(5, 2)) # 5 choose 2 = 10
print("math.perm(5, 2) =", math.perm(5, 2)) # Permutations of 5P2 = 20
Combinatorics math.comb(5, 2) = 10 math.perm(5, 2) = 20
print("GCD, LCM, Modulus")
print("math.gcd(20, 8) =", math.gcd(20, 8)) # 4
print("math.lcm(12, 15) =", math.lcm(12, 15)) # 60
print("math.fmod(20, 3) =", math.fmod(20, 3)) # Remainder (modulus)
print("math.remainder(20, 3) =", math.remainder(20, 3)) # IEEE remainder
GCD, LCM, Modulus math.gcd(20, 8) = 4 math.lcm(12, 15) = 60 math.fmod(20, 3) = 2.0 math.remainder(20, 3) = -1.0
print("Trigonometric")
print("math.sin(math.radians(90)) =", math.sin(math.radians(90))) # sin 90°
print("math.cos(math.radians(0)) =", math.cos(math.radians(0))) # cos 0°
print("math.tan(math.radians(45)) =", math.tan(math.radians(45))) # tan 45°
print("math.degrees(math.pi) =", math.degrees(math.pi)) # Convert pi radians to degrees
print("math.radians(180) =", math.radians(180)) # 180° to radians
Trigonometric math.sin(math.radians(90)) = 1.0 math.cos(math.radians(0)) = 1.0 math.tan(math.radians(45)) = 0.9999999999999999 math.degrees(math.pi) = 180.0 math.radians(180) = 3.141592653589793
print("Inverse Trigonometric")
print("math.asin(1) =", math.asin(1)) # arcsin(1)
print("math.acos(1) =", math.acos(1)) # arccos(1)
print("math.atan(1) =", math.atan(1)) # arctan(1)
print("math.atan2(1, 1) =", math.atan2(1, 1)) # arctan(y/x) handling quadrants
Inverse Trigonometric math.asin(1) = 1.5707963267948966 math.acos(1) = 0.0 math.atan(1) = 0.7853981633974483 math.atan2(1, 1) = 0.7853981633974483
print("Hyperbolic")
print("math.sinh(0) =", math.sinh(0)) # Hyperbolic sine
print("math.cosh(0) =", math.cosh(0)) # Hyperbolic cosine
print("math.tanh(0) =", math.tanh(0)) # Hyperbolic tangent
print("math.asinh(1) =", math.asinh(1)) # Inverse hyperbolic sine
print("math.acosh(1) =", math.acosh(1)) # Inverse hyperbolic cosine
print("math.atanh(0.5) =", math.atanh(0.5)) # Inverse hyperbolic tangent
Hyperbolic math.sinh(0) = 0.0 math.cosh(0) = 1.0 math.tanh(0) = 0.0 math.asinh(1) = 0.881373587019543 math.acosh(1) = 0.0 math.atanh(0.5) = 0.5493061443340548
print("Exponent and Mantissa")
print("math.frexp(8) =", math.frexp(8)) # (mantissa, exponent)
print("math.ldexp(0.5, 4) =", math.ldexp(0.5, 4)) # 0.5 × 2^4 = 8
Exponent and Mantissa math.frexp(8) = (0.5, 4) math.ldexp(0.5, 4) = 8.0
print("Floating Point Summation and Precision Utilities")
print("math.fsum([0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1]) =",math.fsum([0.1] * 10)) # Accurate sum of floats
print("math.isclose(0.1 + 0.2, 0.3) =", math.isclose(0.1 + 0.2, 0.3)) # Check closeness
print("math.ulp(1.0) =", math.ulp(1.0)) # Unit in last place (smallest diff representable)
Floating Point Summation and Precision Utilities math.fsum([0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1]) = 1.0 math.isclose(0.1 + 0.2, 0.3) = True math.ulp(1.0) = 2.220446049250313e-16
print("Geometry & Distance Functions")
print("math.hypot(3, 4) =", math.hypot(3, 4)) # sqrt(3^2 + 4^2)
print("math.dist((0,0), (3,4)) =", math.dist((0,0), (3,4))) # Euclidean distance
print("math.prod([1, 2, 3, 4]) =", math.prod([1, 2, 3, 4])) # Product of list
print("math.isqrt(10) =", math.isqrt(10)) # Integer square root
Geometry & Distance Functions math.hypot(3, 4) = 5.0 math.dist((0,0), (3,4)) = 5.0 math.prod([1, 2, 3, 4]) = 24 math.isqrt(10) = 3
print("Special Functions")
print("math.gamma(5) =", math.gamma(5)) # Gamma(5) = (5-1)!
print("math.lgamma(5) =", math.lgamma(5)) # log(gamma(5))
print("math.erf(1) =", math.erf(1)) # Error function value at 1
print("math.erfc(1) =", math.erfc(1)) # Complementary error function
Special Functions math.gamma(5) = 24.0 math.lgamma(5) = 3.178053830347945 math.erf(1) = 0.8427007929497149 math.erfc(1) = 0.15729920705028513
print("Constants")
print("math.pi =", math.pi) # π
print("math.e =", math.e) # Euler's number e
print("math.inf =", math.inf) # Infinity
print("math.nan =", math.nan) # Not a number (NaN)
Constants math.pi = 3.141592653589793 math.e = 2.718281828459045 math.inf = inf math.nan = nan
# 👷♂️ Meet Bob the Builder: The Math-Savvy Architect!
'''
Bob is designing a pitched roof. He needs to figure out how long the sloping sides should be,
how much area they'll cover, how steep the roof is, how many tiles he’ll need, and what the total cost will be.
Math Concepts Used: Hypotenuse, area, angle, ceiling, degrees.
math.hypot, math.atan, math.degrees, math.ceil, math.floor
'''
# House dimensions
base_width = 8 # in meters
roof_height = 3 # in meters
cost_per_sq_meter = 250 # ₹ per square meter
tile_length = 0.5 # meters
tile_width = 0.5 # meters
# Calculations
slope_length = math.hypot(base_width / 2, roof_height)
roof_area = 2 * (slope_length * base_width / 2)
angle_radians = math.atan(roof_height / (base_width / 2))
angle_degrees = math.degrees(angle_radians)
total_cost = math.ceil(roof_area) * cost_per_sq_meter
tile_area = tile_length * tile_width
num_tiles = math.ceil(roof_area / tile_area)
# Output
print(f"Roof slope length: {slope_length:.2f} meters")
print(f"Roof area: {roof_area:.2f} square meters")
print(f"Roof angle: {angle_degrees:.2f} degrees")
print(f"Estimated cost: ₹{total_cost}")
print(f"Number of tiles needed: {num_tiles}")
Roof slope length: 5.00 meters Roof area: 40.00 square meters Roof angle: 36.87 degrees Estimated cost: ₹10000 Number of tiles needed: 160
'''
Bob wants a beautiful round garden around the house. He calculates the area and
boundary of the circle, how much topsoil is needed, fencing length, and cost estimates.
Math Concepts Used: Area of a circle, circumference, volume, rounding up/down, constants.
math.pi, math.pow, math.ceil, math.floor, math.isclose
'''
radius = 7.5 # meters
depth = 0.3 # meters (topsoil)
cost_per_cubic_meter = 90 # ₹
cost_per_meter_fence = 35 # ₹
# Calculations
area = math.pi * math.pow(radius, 2)
circumference = 2 * math.pi * radius
volume = area * depth
rounded_area = math.ceil(area)
rounded_circumference = math.floor(circumference)
total_soil_cost = math.ceil(volume * cost_per_cubic_meter)
fence_cost = math.ceil(circumference * cost_per_meter_fence)
# Output
print(f"Garden area: {area:.2f} sq meters")
print(f"Garden circumference: {circumference:.2f} meters")
print(f"Topsoil volume: {volume:.2f} cubic meters")
print(f"Total soil cost: ₹{total_soil_cost}")
print(f"Fencing cost: ₹{fence_cost}")
Garden area: 176.71 sq meters Garden circumference: 47.12 meters Topsoil volume: 53.01 cubic meters Total soil cost: ₹4772 Fencing cost: ₹1650
'''
Bob is building a staircase. He needs to know how many steps are required,
how long the stairs will be, the angle for safety, the area for tiling, and if
the slope is within safety limits.
Math Concepts Used: Hypotenuse, tangent, angle, number of steps, area.
math.ceil, math.hypot, math.atan, math.degrees, math.floor
'''
total_height = 3 # meters
step_height = 0.15 # meters
step_depth = 0.30 # meters
# Calculations
num_steps = math.ceil(total_height / step_height)
actual_height = num_steps * step_height
total_depth = num_steps * step_depth
stair_length = math.hypot(actual_height, total_depth)
angle_radians = math.atan(actual_height / total_depth)
angle_degrees = math.degrees(angle_radians)
tread_area = num_steps * step_depth * 1 # 1 meter width
# Output
print(f"Total steps: {num_steps}")
print(f"Actual height: {actual_height:.2f} meters")
print(f"Staircase length: {stair_length:.2f} meters")
print(f"Stair angle: {angle_degrees:.2f} degrees")
print(f"Tread surface area: {tread_area:.2f} sq meters")
Total steps: 20 Actual height: 3.00 meters Staircase length: 6.71 meters Stair angle: 26.57 degrees Tread surface area: 6.00 sq meters
'''Bob is adding a semi-circular arch to the house entrance. He calculates the
curve length, surface area, height needed for equal spacing, and how many bricks will form the arch.
Math Concepts Used: Semi-circle arc, radius, angle, sine/cosine for placement.
math.pi, math.sin, math.cos, math.radians, math.ceil'''
radius = 2.5 # meters
brick_width = 0.3 # meters
thickness = 0.2 # meters
# Calculations
arc_length = math.pi * radius
curve_area = arc_length * thickness
height = radius
num_bricks = math.ceil(arc_length / brick_width)
angle_per_brick = 180 / num_bricks
first_angle = math.radians(angle_per_brick)
# Output
print(f"Arc length: {arc_length:.2f} meters")
print(f"Curve surface area: {curve_area:.2f} sq meters")
print(f"Arch height: {height} meters")
print(f"Bricks needed: {num_bricks}")
print(f"Angle between bricks: {angle_per_brick:.2f} degrees")
Arc length: 7.85 meters Curve surface area: 1.57 sq meters Arch height: 2.5 meters Bricks needed: 27 Angle between bricks: 6.67 degrees
'''
Bob is constructing a cylindrical water tank behind the house.
He needs to know the tank’s surface area for painting, volume for
water capacity, and cost estimation.
Math Concepts Used: Cylinder volume, surface area, pi constant, rounding.
math.pi, math.pow, math.ceil, math.floor, math.isclose
'''
radius = 1.2 # meters
height = 2.5 # meters
paint_cost_per_sqm = 45 # ₹ per sq meter
water_cost_per_litre = 0.07 # ₹ per litre
# Calculations
lateral_area = 2 * math.pi * radius * height
circle_area = math.pi * math.pow(radius, 2)
total_surface_area = lateral_area + 2 * circle_area
volume_cubic_m = circle_area * height
volume_litres = volume_cubic_m * 1000
painting_cost = math.ceil(total_surface_area * paint_cost_per_sqm)
water_cost = math.floor(volume_litres * water_cost_per_litre)
# Output
print(f"Tank surface area: {total_surface_area:.2f} sq meters")
print(f"Water volume: {volume_litres:.2f} litres")
print(f"Painting cost: ₹{painting_cost}")
print(f"Water fill cost: ₹{water_cost}")
Tank surface area: 27.90 sq meters Water volume: 11309.73 litres Painting cost: ₹1256 Water fill cost: ₹791
# change the values and formulae and explore more!
# Random
import random
print(dir(random))
['BPF', 'LOG4', 'NV_MAGICCONST', 'RECIP_BPF', 'Random', 'SG_MAGICCONST', 'SystemRandom', 'TWOPI', '_ONE', '_Sequence', '_Set', '__all__', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__', '_accumulate', '_acos', '_bisect', '_ceil', '_cos', '_e', '_exp', '_floor', '_index', '_inst', '_isfinite', '_log', '_os', '_pi', '_random', '_repeat', '_sha512', '_sin', '_sqrt', '_test', '_test_generator', '_urandom', '_warn', 'betavariate', 'choice', 'choices', 'expovariate', 'gammavariate', 'gauss', 'getrandbits', 'getstate', 'lognormvariate', 'normalvariate', 'paretovariate', 'randbytes', 'randint', 'random', 'randrange', 'sample', 'seed', 'setstate', 'shuffle', 'triangular', 'uniform', 'vonmisesvariate', 'weibullvariate']
# random(): random float in [0.0, 1.0)
print("random.random() =", random.random()) # Random float between 0.0 and 1.0
# randint(a, b): integer in [a, b]
print("random.randint(1, 6) =", random.randint(1, 6)) # Random integer between 1 and 6 (inclusive)
# uniform(a, b): float in [a, b]
print("random.uniform(1.5, 10.5) =", random.uniform(1.5, 10.5)) # Random float between 1.5 and 10.5
# randrange(start, stop[, step])
print("random.randrange(1, 10, 2) =", random.randrange(1, 10, 2)) # Random odd number between 1 and 10
# choice(seq): randomly select an element from a sequence
print("random.choice(['apple', 'banana', 'cherry']) =", random.choice(['apple', 'banana', 'cherry'])) # Random element from list
# choices(population, weights=None, k=1): list of k elements with replacement
print("random.choices(['red', 'blue', 'green'], weights=[10, 1, 1], k=3) =", random.choices(['red', 'blue', 'green'], weights=[10, 1, 1], k=3)) # Randomly choose 3 items, biased to pick 'red'
# sample(population, k): list of k unique elements from population
print("random.sample([1, 2, 3, 4, 5], 2) =", random.sample([1, 2, 3, 4, 5], 2)) # Random 2 items from list, without replacement
# shuffle(x): shuffle a sequence in place
lst = [1, 2, 3, 4]
random.shuffle(lst)
print("random.shuffle([1, 2, 3, 4]) =", lst) # Shuffle list in place
random.random() = 0.36140299680641375 random.randint(1, 6) = 4 random.uniform(1.5, 10.5) = 8.74802635459081 random.randrange(1, 10, 2) = 9 random.choice(['apple', 'banana', 'cherry']) = cherry random.choices(['red', 'blue', 'green'], weights=[10, 1, 1], k=3) = ['red', 'red', 'red'] random.sample([1, 2, 3, 4, 5], 2) = [1, 5] random.shuffle([1, 2, 3, 4]) = [3, 1, 2, 4]
# betavariate(alpha, beta): Beta distribution
print("random.betavariate(2, 5) =", random.betavariate(2, 5)) # Random float from Beta distribution
# expovariate(lambd): Exponential distribution
print("random.expovariate(1.5) =", random.expovariate(1.5)) # Random float from Exponential distribution
# gammavariate(alpha, beta): Gamma distribution
print("random.gammavariate(2, 3) =", random.gammavariate(2, 3)) # Random float from Gamma distribution
# gauss(mu, sigma): Gaussian (normal) distribution
print("random.gauss(0, 1) =", random.gauss(0, 1)) # Random float from Normal distribution with mean 0 and std deviation 1
# lognormvariate(mu, sigma): Log-normal distribution
print("random.lognormvariate(0, 0.5) =", random.lognormvariate(0, 0.5)) # Random float from Log-normal distribution
# normalvariate(mu, sigma): Normal distribution
print("random.normalvariate(100, 15) =", random.normalvariate(100, 15)) # Random float from Normal distribution with mean 100 and std deviation 15
# paretovariate(alpha): Pareto distribution
print("random.paretovariate(2.5) =", random.paretovariate(2.5)) # Random float from Pareto distribution
# triangular(low, high, mode): Triangular distribution
print("random.triangular(1, 10, 5) =", random.triangular(1, 10, 5)) # Random float from Triangular distribution
# vonmisesvariate(mu, kappa): Circular (Von Mises) distribution
print("random.vonmisesvariate(0, 4) =", random.vonmisesvariate(0, 4)) # Random float from Von Mises distribution
# weibullvariate(alpha, beta): Weibull distribution
print("random.weibullvariate(1, 1.5) =", random.weibullvariate(1, 1.5)) # Random float from Weibull distribution
random.betavariate(2, 5) = 0.5484775678490088 random.expovariate(1.5) = 0.1958462273940966 random.gammavariate(2, 3) = 16.29316138540588 random.gauss(0, 1) = -1.3421940643242969 random.lognormvariate(0, 0.5) = 1.3598623435514137 random.normalvariate(100, 15) = 106.76097954463624 random.paretovariate(2.5) = 2.5492886907343095 random.triangular(1, 10, 5) = 4.341399281789078 random.vonmisesvariate(0, 4) = 6.073381104436034 random.weibullvariate(1, 1.5) = 0.31110331885116
# seed(a=None): Initializes the random number generator
random.seed(42)
print("random.seed(42)")
# getstate(): Get the current state of the RNG
state = random.getstate()
print("random.getstate() =", state)
# setstate(state): Set the state of the RNG
random.setstate(state)
print("random.setstate(state)")
# getrandbits(k): Returns a random integer with `k` random bits
print("random.getrandbits(8) =", random.getrandbits(8)) # Random integer with 8 bits
# randbytes(n): Returns `n` random bytes
print("random.randbytes(4) =", random.randbytes(4)) # 4 random bytes
random.seed(42) random.getstate() = (3, (2147483648, 3564348608, 1266698288, 4212342371, 3595291661, 3180588708, 3037210256, 946923017, 2565409715, 2900535780, 924383152, 4180157270, 4230508198, 2039675917, 3755350407, 2362848650, 2818100609, 2097423432, 524478045, 540883378, 281170210, 1485176884, 1493190386, 1773214509, 380915208, 3667698522, 2648371337, 2961234806, 3857480267, 1582950522, 246289694, 3322185604, 1944574775, 302623699, 169865066, 1143540808, 3733177770, 513116636, 1411153081, 3205493053, 768926902, 549624109, 1470655403, 59539609, 3678480009, 3087139671, 1176835859, 2078491503, 2299934332, 1592059249, 1062716176, 2654193596, 3531838733, 2661260596, 3881209635, 2106865768, 4154287292, 2082185616, 2301197011, 2177349827, 3082181756, 1787663536, 3714670796, 3018262113, 1670056238, 1856738750, 99824592, 2279837081, 1414647942, 3416675731, 3458782472, 3997022236, 468762002, 2666158583, 953353270, 1788980658, 3802061067, 407586584, 1844776834, 1906917274, 3154715663, 3028370222, 4156024188, 3996363428, 80495456, 2659800972, 2005649973, 3818358673, 3952623596, 2506862371, 3282302532, 263923435, 3384662671, 3292439172, 3119957588, 1224426111, 899864150, 215262826, 1619647231, 3347694949, 3497868538, 2029552053, 2992804824, 4080010250, 2023513186, 1885979437, 3564622190, 3775424270, 2297810139, 3549449169, 2664856277, 3274801974, 2794883969, 980412666, 2980215653, 2794389321, 2816521934, 1266970739, 542306338, 3646225311, 3598997630, 2111980720, 2949252482, 2489027658, 352815024, 11610683, 1386663624, 2004196796, 1161461546, 1921293780, 2463949525, 1647009713, 3550093655, 2563894064, 3486310554, 1506105865, 243092931, 2659437476, 4200687059, 2284345122, 1974438610, 3591096528, 967119212, 3362401375, 140678365, 311602112, 2361740275, 2139598582, 3632873481, 2762232439, 4156482318, 381637792, 3253346525, 2492118775, 1502434558, 3164497290, 3550998357, 2412448305, 2223955385, 4122879535, 350121793, 1835149778, 2175117867, 989674750, 3178241202, 3553093569, 3470650311, 2829698151, 3209427769, 1779174943, 275388428, 4044574515, 715447260, 3180940440, 4020772289, 1322708567, 3189868792, 4250485633, 716970023, 2307550151, 1074996711, 1217573599, 197006094, 2178394212, 1255233746, 4164251484, 1405608772, 2808160475, 1304736088, 1796071066, 2761748078, 3570739698, 1616118556, 2232868135, 3567541936, 3470600401, 3031621994, 3351764214, 1359785149, 2617497797, 3340028190, 356162828, 2083806068, 2503635608, 4024838996, 2577080371, 2897993505, 3120733934, 905794891, 2506078507, 4211618666, 3777871979, 809751414, 4080874167, 1562977008, 3917373055, 2132779194, 4014249473, 4067327082, 2582869847, 1780081876, 1842619106, 3381761227, 921004274, 1393256920, 1883566732, 2702071861, 865327389, 1622085203, 3021825820, 2687061406, 1748902923, 689023977, 308399650, 2377287978, 1646969411, 1051806316, 4277884230, 2041056290, 101134519, 2032472116, 4112521069, 151202901, 2773743461, 551348559, 3476836808, 510935951, 625057077, 3757450756, 2977698135, 3027776859, 2616998041, 2773430005, 544190486, 2241368212, 1141105829, 1452816309, 4199229235, 3218013033, 4229475816, 1659576351, 3020348754, 1193400518, 3208584597, 1151197733, 2597187966, 503065140, 2421841572, 1437291709, 1909275895, 2872630545, 793588217, 3792934707, 1784451785, 2921385648, 1669902526, 4189978976, 1196986251, 434805516, 1907541826, 2624415034, 1687778718, 650746582, 1949153382, 4148493093, 841300520, 1164202054, 4203468658, 4106300911, 850346789, 1715730760, 3114661489, 2866524548, 1360448945, 3601318775, 1743078223, 2413855408, 1211895622, 325117146, 2721152875, 1284334485, 2446538832, 739014618, 2237045115, 842553465, 2538598293, 746460793, 4010387366, 2002655192, 4193733112, 1194380773, 3918217378, 1447487475, 5659228, 3408847694, 4190318700, 1862549564, 781683719, 1194618118, 755053413, 3436011942, 2885435303, 3081151348, 2017642831, 1053816502, 1086627485, 2157296554, 110650022, 965352898, 1003174194, 1288956241, 4057404871, 2965068465, 2897064481, 2457377317, 1879872545, 358455290, 375086701, 3015902095, 1676249984, 924455526, 2084169389, 1989014644, 1993749926, 2009424973, 2113340508, 3980883273, 2915977458, 203328382, 3020815229, 2415050113, 4103009585, 3700885489, 2916647550, 1523006503, 174302338, 2476909338, 1969322490, 4285741984, 1528449097, 3355315515, 4217241278, 599579127, 2572243673, 3035856735, 1539140489, 1782314913, 4238644287, 1746424142, 1978148312, 2380746849, 184941882, 1106717981, 1720750349, 981701307, 3953154731, 3257809181, 2892339376, 3339778166, 3676936849, 87425948, 3029257381, 2037942523, 3807628706, 2861474706, 1058852346, 1322765211, 2686046342, 2689342655, 2303436168, 2571627181, 1986057734, 1183564308, 2829677523, 1295563975, 503126586, 2025890348, 4179277821, 1735262467, 981331774, 1613447066, 1011606109, 2000062246, 3581448390, 3477731384, 3641307373, 3508544379, 2327233491, 3931944343, 4189052882, 2990416380, 422406169, 202291313, 2531006461, 4277024116, 3815144003, 821314585, 1344175168, 3562834071, 1339615445, 1831545190, 3115548822, 743512780, 4006999448, 3720181735, 1012033521, 919931041, 2628967879, 1151876565, 1268107129, 3674829936, 834977846, 743987006, 3947536548, 3706529695, 4121073678, 2507605742, 1595636918, 2708047833, 2427507331, 3868216331, 3254240010, 2097683411, 3279710596, 3686819053, 1843541720, 1683793619, 3245287285, 3571828776, 3733296431, 3806747478, 1390930605, 3860422228, 114397037, 1931519825, 2770684378, 1556101783, 1436111731, 4031950081, 562876656, 1775895782, 612364620, 1313509772, 4283410242, 3252958463, 2176555836, 3933073367, 3013277102, 1444071961, 3120949516, 2824578890, 325676929, 943677134, 1800649256, 1721927060, 347498719, 1435221321, 2623572981, 1408548470, 4145586315, 2901889237, 1849377952, 1239144551, 3382598266, 2992893897, 3738297588, 611280106, 3897415338, 2370299241, 1772308583, 3697465753, 354508058, 2702360134, 591308331, 3524072501, 976616000, 2563717192, 3078266097, 1376594703, 4209795919, 2454412767, 2712206031, 2963860163, 3734324882, 2248653800, 324872786, 3789837448, 3779000146, 527733939, 2844165793, 576499681, 1618787435, 2638888650, 57511068, 2804627518, 2993670030, 481402236, 2810124845, 1416045214, 1723694191, 1214944572, 3188123783, 1139185907, 3851015362, 1719652470, 1661343029, 3644307578, 3564178709, 1256656955, 46631590, 4231317929, 3098958589, 1834956625, 2206185428, 3695688374, 3647957317, 1064098871, 1739100906, 2579568980, 27974051, 2617466775, 964075233, 907049942, 4164146575, 3377168066, 2524828266, 1083546008, 2992960953, 2260789066, 1543742095, 2843842831, 1375722284, 3574521313, 110842534, 2310998251, 3076511734, 783145600, 1287776608, 3087144146, 305559823, 2356293719, 3228441476, 1678938122, 3775814061, 1620283952, 2512027726, 1031432407, 962295099, 3877418501, 968669928, 304126693, 3711291137, 3847527101, 494066767, 4050229756, 4169448589, 671763915, 1095747781, 4006132710, 394725957, 200521654, 2715998750, 1477567673, 895171901, 3370105999, 2684157455, 4153990023, 3966076501, 2043374409, 144443759, 6764556, 1611650045, 1480956755, 1388276468, 4136518438, 1538041336, 266773992, 1623357516, 2267298390, 3183919402, 1084292424, 2796136160, 2413448816, 2850375199, 3510894040, 2644778623, 3317288284, 3697317540, 1465776787, 1843489446, 1416711171, 744701117, 1286781349, 3748640476, 861982119, 2377742909, 1171768136, 2701877439, 3839724288, 2869791015, 2386067954, 2629214347, 955801623, 3831079317, 624), None) random.setstate(state) random.getrandbits(8) = 163 random.randbytes(4) = b'\x7f1\x80\x1c'
# Dora's Magical Number Adventure
'''
Dora the Explorer is playing a fun number guessing game in a magical forest! In each round:
A secret number is chosen randomly between 1 and 20.
Dora makes a random guess.
If she guesses the number correctly or gets lucky with a miracle, she wins magical gifts!
The number of rounds, gifts, and points she earns are all randomly determined.
Your task is to simulate this game using Python's random module to:
Decide how many rounds Dora will play.
Generate a random secret number and Dora’s guess in each round.
Randomly decide if a miracle happens.
Reward Dora with random gifts and points if she wins.
Display Dora’s final magical score and total gifts.
| Random Function | Purpose in the Game |
|----------------------------------|--------------------------------------------------------------------|
| random.randint(a, b) | Picks total rounds (5–10), secret number (1–20), gift count (1–3) |
| random.randrange(a, b) | Dora's guess (1–20) |
| random.triangular(0, 1, 0.7) | Simulates miracle chance (biased toward 0.7) |
| random.betavariate(2, 5) | Used as a multiplier to vary Dora's magical score |
| random.uniform(5, 15) | Determines random points earned when Dora wins |
| random.choices() | Selects multiple gifts from the pool, allowing duplicates |
| random.shuffle() | Randomizes the gift pool before selection |
| random.choice() | Chooses a motivational quote randomly from Dora |
'''
import random
print("🌟 Dora the Explorer's Ultimate Number Adventure Game 🌟")
# Dora's magical gift collection
gift_pool = [
"Magic Map 🗺️", "Backpack 🎒", "Flying Boots 👢", "Invisible Cloak 🕶️",
"Talking Compass 🧭", "Rainbow Seeds 🌈", "Healing Potion 🧪",
"Teleport Stone 💠", "Golden Banana 🍌", "Bouncing Berries 🍓",
"Crystal Crown 👑", "Enchanted Whistle 🎵"
]
# Dora’s motivational quotes
quotes = [
"We did it, hooray! 🎉", "Let’s go explore! 🗺️", "Swiper, no swiping! 🙅",
"Lo hicimos! 🎊", "Adventure awaits! 🚀", "Anything is possible! 🌈"
]
# Total random number of rounds between 5 to 10
total_rounds = random.randint(5, 10)
print(f"\n🌀 Dora is playing {total_rounds} magical rounds!\n")
# Dora’s magical score and gift tracker
dora_score = 0.0
total_gifts = 0
for round_num in range(1, total_rounds + 1):
print(f"🔮 Round {round_num}:")
# Dora's guess and the secret number
secret_number = random.randint(1, 20)
dora_guess = random.randrange(1, 21)
print(f" Dora guessed: {dora_guess}")
print(f" Secret number: {secret_number}")
# Add randomness to bonus logic
miracle_chance = random.triangular(0, 1, 0.7)
magic_multiplier = random.betavariate(2, 5)
print(f" Miracle Chance: {round(miracle_chance, 2)}")
if dora_guess == secret_number or miracle_chance > 0.6:
# Shuffle and choose 1–3 random gifts
random.shuffle(gift_pool)
gift_count = random.randint(1, 3)
gifts = random.choices(gift_pool, k=gift_count)
score_add = random.uniform(5, 15) * magic_multiplier
dora_score += score_add
total_gifts += gift_count
print(f" 🎉 Dora wins! Received miracle gift(s): {', '.join(gifts)}")
print(f" 🌟 {random.choice(quotes)} (+{round(score_add, 2)} points)")
else:
print(" 😢 Dora didn’t win this time...")
print(f" ✨ Current magic score: {round(dora_score, 2)}\n")
# Final magical summary
print("🌈 Game Over!")
print(f"🔢 Total Rounds Played: {total_rounds}")
print(f"🌟 Dora's Final Magic Score: {round(dora_score, 2)}")
print(f"📦 Total Miracle Gifts Received: {total_gifts} 🎁")
🌟 Dora the Explorer's Ultimate Number Adventure Game 🌟 🌀 Dora is playing 5 magical rounds! 🔮 Round 1: Dora guessed: 8 Secret number: 9 Miracle Chance: 0.4 😢 Dora didn’t win this time... ✨ Current magic score: 0.0 🔮 Round 2: Dora guessed: 8 Secret number: 7 Miracle Chance: 0.59 😢 Dora didn’t win this time... ✨ Current magic score: 0.0 🔮 Round 3: Dora guessed: 15 Secret number: 8 Miracle Chance: 0.64 🎉 Dora wins! Received miracle gift(s): Teleport Stone 💠, Rainbow Seeds 🌈, Invisible Cloak 🕶️ 🌟 Anything is possible! 🌈 (+4.22 points) ✨ Current magic score: 4.22 🔮 Round 4: Dora guessed: 12 Secret number: 20 Miracle Chance: 0.64 🎉 Dora wins! Received miracle gift(s): Teleport Stone 💠, Golden Banana 🍌, Golden Banana 🍌 🌟 Anything is possible! 🌈 (+2.07 points) ✨ Current magic score: 6.29 🔮 Round 5: Dora guessed: 6 Secret number: 8 Miracle Chance: 0.57 😢 Dora didn’t win this time... ✨ Current magic score: 6.29 🌈 Game Over! 🔢 Total Rounds Played: 5 🌟 Dora's Final Magic Score: 6.29 📦 Total Miracle Gifts Received: 6 🎁