Thursday, November 5, 2020

Simple python program

 import random



def add(list1):

  c=0

  for x in list1:

    c+=x

  return c 


def mean(c):

  result=c/9

  return result

  

def median(list1,n):

  ##odd

  if (n+1)%2==0:

    x=int((n+1)/2)

    val=list1[x-1]

    return val 

    ##even

  else:

    d=int((n+1)/2)

    return((list1[d]+list1[d-1])/2)



    

def calculate():

  list1=[]

  

  

  n=int(input("enter the number of integers"))


  for x in range(1,(n+1)):

    list1.append(random.randint(12,30))

  #printing random list1 

  print(list1)


  #summing of list1

  print(add(list1))


  ##printing mean of list1

  c=add(list1)

  print(mean(c))

  print(list1)


  # printing median

  print(median(list1,n))


calculate()

No comments:

Post a Comment