Program3(a)
3.a. Read N numbers from the console and create a list. Develop a program to print mean, variance and standard deviation with suitable messages.
Objective of the Program
To understand list creation from user input
To perform statistical calculations
To use loops for computation
To apply mathematical formulas in programming
Logical Construction (Think Before You Code)
Before writing the program, understand the mathematical formulas clearly.
Suppose the list contains N numbers:
x1, x2, x3, ... , xN
1.Mean (Average)
2.Variance
Subtract mean from each element
Square the result
Add all squared values
Divide by N
3.Standard Deviation
Program Logic Steps
Read N
Create empty list
Read N numbers and store in list
Compute sum
Calculate mean
Compute squared differences
Calculate variance
Calculate standard deviation
Display results
👉 The key idea:
First compute mean, then use it to compute variance, then compute standard deviation.
Flowchart (Block Diagram of Logic)
Start
Read N
Input N numbers into list
Calculate sum
Compute mean
Compute variance
Compute standard deviation
Display results
Stop
Algorithm
Start
Read N
Initialize empty list
For i from 1 to N
Read number
Append to list
Calculate sum of list
Compute mean = sum / N
Initialize variance_sum = 0
For each element in list
variance_sum += (element − mean)²
variance = variance_sum / N
standard_deviation = √variance
Display mean, variance, standard deviation
Stop
Python Program
⚠ Students must complete the missing parts.
# Program to calculate Mean, Variance and Standard Deviation
import math
n = int(input("Enter number of elements: "))
numbers = []
for i in range(n):
value = float(input("Enter number: "))
numbers.append(__________)
total = sum(__________)
mean = total / __________
variance_sum = 0
for num in numbers:
variance_sum += (num - __________) ** 2
variance = variance_sum / __________
std_deviation = math.sqrt(____________)
print("Mean =", mean)
print("Variance =", variance)
print("Standard Deviation =", std_deviation)
Probable Output
Case 1
Important Concepts Used
Lists
sum()functionLooping (
for)Arithmetic operations
math.sqrt()Statistical formulas
Viva Voce Questions
What is mean?
What is variance?
Why do we square the difference?
Why is standard deviation square root of variance?
Can variance be negative?
What happens if N = 0?
What is the time complexity of this program?
Procedure to Execute the Program
Open Python IDLE / VS Code / Google Colab
Create a new file
Type the program
Save with
.pyextensionRun the program
Enter N and the numbers
Google Colab – Online Execution
👉 Paste your Colab link here.
[https://colab.research.google.com/drive/1cUDbj_f5HZbs5k4mlgX5YLK3ONXcub2A?usp=sharing]
Program Explanation
Assignment for Students
Modify program to calculate sample variance
Use
statisticsmodule instead of manual calculationStore results in a dictionary
Display results rounded to 2 decimal places
Lab Record Instructions
Right Side of the Record
1. Problem Statement
2. Python Program
Write the following neatly on the right-hand side page:
Left Side of the Record
Write the following neatly on the left-hand side page:
3. Flowchart
4. Algorithm
5. Output
⚠️ Students must write ALL possible outputs.

Comments
Post a Comment