Python Practical Practice Word
Python Practical Practice Word
Write a program that finds the sum of all multiples of 3 and 5 below 1000 using a
for loop.
Q2. Write a program that asks the user to guess a number between 1 and 10. The pro-
gram should repeatedly ask the user to guess the number until they get it right, and
keep track of how many guesses it took.
Q3. Write a program that creates a NumPy array of random integers and calculates
the mean, median, and mode.
Q4. Write a program that uses a for loop to iterate over a NumPy array and print the
square of each element.
Q5. Plot a line graph for the function y = 2x + 1 for x values between -10 and 10.
Q6. Write a program to generate a scatter plot of random points. Use 50 random x and
y points.
Q7. Generate 1000 random numbers from a normal distribution using NumPy and plot
a histogram.
Q8. Create a bar graph that shows the number of students in different classes (e.g.,
Class A: 30, Class B: 25, Class C: 35, Class D: 20).
Q9.Write a program to plot a box plot of 3 sets of random data using Matplotlib.
Q10. Write a program to perform element-wise addition, subtraction, multiplication, di-
vision, floor division, and remainder on the following two NumPy arrays
2.
import random
3.
import numpy as np
from scipy import stats
mean_value = np.mean(data)
median_value = np.median(data)
mode_value = stats.mode(data)[0][0]
print(f"Array: {data}")
print(f"Mean: {mean_value}, Median: {median_value}, Mode: {mode_value}”)
4.
import numpy as np
5.
import numpy as np
import matplotlib.pyplot as plt
6.
import numpy as np
import matplotlib.pyplot as plt
x = np.random.rand(50)
y = np.random.rand(50)
plt.scatter(x, y)
plt.title("Random Scatter Plot")
plt.xlabel("X axis")
plt.ylabel("Y axis")
plt.show()
7.
import numpy as np
import matplotlib.pyplot as plt
data = np.random.randn(1000)
8.
import matplotlib.pyplot as plt
plt.bar(classes, students)
plt.title("Number of Students in Each Class")
plt.xlabel("Classes")
plt.ylabel("Number of Students")
plt.show()
9.
import numpy as np
import matplotlib.pyplot as plt
data1 = np.random.normal(0, 1, 100)
data2 = np.random.normal(5, 2, 100)
data3 = np.random.normal(-2, 0.5, 100)
10.
import numpy as np
# Element-wise addition
add_result = array1 + array2
print(f"Addition: {add_result}")
# Element-wise subtraction
sub_result = array1 - array2
print(f"Subtraction: {sub_result}")
# Element-wise multiplication
mul_result = array1 * array2
print(f"Multiplication: {mul_result}")
# Element-wise division
div_result = array1 / array2
print(f"Division: {div_result}")
# Element-wise remainder
remainder_result = array1 % array2
print(f"Remainder: {remainder_result}")