Robotics & Artificial Intelligence

Python modules offer a wide range of functionality. The math and random modules are some of the most commonly used modules in programming. The random module is used to generate random numbers, and the math module provides mathematical functions like sqrt() and factorial().

Write a program that generates a random integer between 1 and 100 using the random module. Then, use the math module to calculate the square root of the generated number.

Python Functions

2 Likes

Answer

import random
import math
num = random.randint(1, 100)
print("Random number:", num)
result = math.sqrt(num)
print("Square root of the number:", result)

Output

Random number: 66
Square root of the number: 8.12403840463596

Random number: 81
Square root of the number: 9.0

Answered By

3 Likes


Related Questions