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.
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 ratings0% 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.
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