0% found this document useful (0 votes)
15 views2 pages

3 and 4-Python Lab

The document describes two Python programs. The first program reads N numbers from the console, calculates, and prints the mean, variance, and standard deviation of the numbers. The second program reads a multi-digit number as characters and prints the frequency of each digit entered.

Uploaded by

deeksha31005
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views2 pages

3 and 4-Python Lab

The document describes two Python programs. The first program reads N numbers from the console, calculates, and prints the mean, variance, and standard deviation of the numbers. The second program reads a multi-digit number as characters and prints the frequency of each digit entered.

Uploaded by

deeksha31005
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

3. Read N numbers from the console and create a list.

Develop a program to
print mean, variance and standard deviation with suitable messages.

from math import sqrt


myList = []
num = int(input("Enter the number of elements in your list : "))
for i in range(num):
val = int(input("Enter the element : "))
myList.append(val)
print('The length of list1 is', len(myList))
print('List Contents', myList)
total = 0
for elem in myList:
total += elem
mean = total / num
total = 0
for elem in myList:
total += (elem - mean) * (elem - mean)
variance = total / num
stdDev = sqrt(variance)
print("Mean =", mean)
print("Variance =", variance)
print("Standard Deviation =", "%.2f"%stdDev)
OUTPUT
Enter the number of elements in your list : 5
Enter the element : 45
Enter the element : 34
Enter the element : 86
Enter the element : 92
Enter the element : 35
The length of list1 is 5
List Contents [45, 34, 86, 92, 35]
Mean = 58.4
Variance = 642.64
Standard Deviation = 25.35
4. Read a multi-digit number (as chars) from the console. Develop a program
to print the frequency of each digit with suitable message.

num = input("Enter a number : ")


print("The number entered is :", num)
uniqDig = set(num)
for elem in uniqDig:
print(elem, "occurs", num.count(elem), "times")

OUTPUT

Enter a number : 23499


The number entered is : 23499
9 occurs 2 times
3 occurs 1 times
2 occurs 1 times
4 occurs 1 times

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy