MODEL QUESTIONS
RANDOM MODULE
1. What is the difference between [Link]() and [Link](a, b)?
Answer: [Link]() returns a random floating-point number between 0.0 and
1.0 (exclusive of 1.0). [Link](a, b) returns a random floating-point number
between two specified numbers
2. Which function is used to shuffle elements in a list, and what is its return type?
Answer: [Link]() is used. It shuffles the elements in place, meaning it
modifies the original list and returns None
3. What are the possible outputs?
import random
L = [10, 20, 30, 40, 50]
print([Link](L), [Link](1, 3))
Answer: [Link] picks one element from the list. randint(1, 3) returns an
integer N where 1 ≤ N ≤ 3 (inclusive). Possible outputs include 10 1, 50 3, 30 2, etc
4. What is the purpose of [Link](x)
It initializes the pseudo-random number generator. Using the same seed ensures
that the same sequence of random numbers is generated, which is useful for
debugging or creating reproducible results
5. Explain [Link](start, stop, step) with an example.
Answer: Returns a randomly selected element from range(start, stop, step). It does
not actually build a list. Example: [Link](0, 10, 2) can return 0, 2, 4, 6, or
8
6. Write a program to generate 3 random integers between 100 and 999 which are
divisible by 5.
7. Write a program to simulate a dice roll (1 to 6)
8. Write a program that accepts the length of three sides of a triangle and determines
if it is an equilateral triangle
9. What will be the output?
import random
NAV = ["LEFT", "FRONT", "RIGHT", "BACK"]
NUM = [Link](1, 2)
for I in range(NUM):
print(NAV[I], end=":")
10. Write a program to calculate the area of a circle using the math module.
import math
radius = float(input("Enter radius: "))
area = [Link] * [Link](radius, 2)
print("Area:", round(area, 2))
11. import random
L = ['A', 'B', 'C']
print([Link](L))
If the above code is executed 10,000 times, will each element appear equally?
Write a program to verify experimentally.
12. import random
[Link](10)
print([Link](1,100))
[Link](10)
print([Link](1,100))
Predict the output of the above code (same or different) and justify
your answer.
13. List out the types of Modules and Explain any two types in
detail.
14. Explain how to create a user defined module in Python.
MATH MODULE
A municipality wants to fence a circular park with radius 28 meters. Write a Python
program using the math module to calculate:
1. The circumference of the park
2. The cost of fencing if cost per meter is ₹15
Use appropriate functions/constants from the math module.
import math
Program:
radius = int(input(“Enter radius”))
cost_per_meter = int(input(“Enter Cost per meter”))
circumference = 2 * [Link] * radius
total_cost = circumference * cost_per_meter
print("Circumference of the park:", circumference)
print("Total fencing cost (₹):", total_cost)
A calculator application should compute square roots. Write a Python program using
[Link]() that:
1. Accepts user input
2. Handles invalid input (negative numbers) gracefully