Thursday, 16 January 2020

Write a algorithm and python program to implement statistics (import statistics- mean, median and mode)


# a) mean   (it returns the average value of the set/sequence of value passed

import statistics as s
a=eval(input("Enter the size "))
seq=[]
for i in range(a):
    n=eval(input("Enter the elements "))
    seq.append(n)
mea=s.mean(seq)
print("The mean /average value is =",mea)

output
Enter the size 12
Enter the elements 5
Enter the elements 6
Enter the elements 7
Enter the elements 5
Enter the elements 6
Enter the elements 5
Enter the elements 5
Enter the elements 9
Enter the elements 11
Enter the elements 12
Enter the elements 23
Enter the elements 5
The mean /average value is = 8.25

#b) median 

#The median() function returns the median (middle value) of numeric data. When a number # of data points are odd, return the middle data point. When the number of data points is
 # even, a median is interpolated by taking the average of the two middle

import statistics as s
a=eval(input("Enter the size: "))
seq=[]
for i in range(a):
    n=eval(input("Enter the elements: "))
    seq.append(n)
mead=s.median(seq)
print("Elements =",seq)
print("The median value is =",mead)

output (even size)
Enter the size: 12
Enter the elements: 5
Enter the elements: 6
Enter the elements: 7
Enter the elements: 5
Enter the elements: 6
Enter the elements: 5
Enter the elements: 5
Enter the elements: 9
Enter the elements: 11
Enter the elements: 12
Enter the elements: 23
Enter the elements: 5
Elements = [5, 6, 7, 5, 6, 5, 5, 9, 11, 12, 23, 5]
The median value is = 6.0

Enter the size: 11 (size=odd)
Enter the elements: 5
Enter the elements: 6
Enter the elements: 7
Enter the elements: 5
Enter the elements: 16
Enter the elements: 55
Enter the elements: 5
Enter the elements: 5
Enter the elements: 16
Enter the elements: 11
Enter the elements: 12
Elements = [5, 6, 7, 5, 16, 55, 5, 5, 16, 11, 12]
The median value is = 7

# c) mode program (it returns the most often repeated value of the set)

import statistics as s
a=eval(input("Enter the size: "))
seq=[]
for i in range(a):
    n=eval(input("Enter the elements: "))
    seq.append(n)
mod=s.mode(seq)
print("Elements =",seq)
print("The median value is =",mod)

Output
Enter the size: 12
Enter the elements: 5
Enter the elements: 6
Enter the elements: 7
Enter the elements: 5
Enter the elements: 6
Enter the elements: 5
Enter the elements: 5
Enter the elements: 9
Enter the elements: 11
Enter the elements: 12
Enter the elements: 23
Enter the elements: 5
Elements = [5, 6, 7, 5, 6, 5, 5, 9, 11, 12, 23, 5]
The median value is = 5


1 comment:

  1. Computer science (sometimes called computation science) is the study of processes that interact with data and that can be represented as data in the form of programs. It enables the use of algorithms to manipulate, store, and communicate digital information. A computer scientist studies the theory of computation and the practice of designing software systems.
    UGC care journals for Computer science,
    Its fields can be divided into theoretical and practical disciplines. Computational complexity theory is highly abstract, while computer graphics emphasizes real-world applications. Programming language theory considers approaches to the description of computational processes, while software engineering involves the use of programming languages and complex systems. Human–computer interaction considers the challenges in making computers useful, usable, and accessible.

    ReplyDelete