Program 12
Write a program that generates a list of 20 random numbers between 1 and 100.
(a) Print the list.
(b) Print the average of the elements in the list.
(c) Print the largest and smallest values in the list.
(d) Print the second largest and second smallest entries in the list
(e) Print how many even numbers are in the list.
import random
l=[]
for num in range(20):
l.append(random.randint(1,100))
print("List Elements are:",l)
avg=sum(l)/len(l)
print("The Average of the Elements in the list is=",avg)
print("Largest Value in the list is :",max(l))
print("Smallest Value in the list is :",min(l))
l1=sorted(l)
print("second Largest value in the List is:",l1[-2])
print("Second smallest value in the List is:",l1[1])
count=0
for i in l1:
if (i%2==0):
count=count+1
print("Number of Even Number in the List is :",count)
OUTPUT:
========RESTART: D:\old\r19 lab-python\12.py =======
List Elements are: [23, 72, 37, 86, 9, 54, 9, 78, 32, 40, 12, 3, 54, 65, 49, 88, 98, 70, 51, 82]
The Average of the Elements in the list is= 50.6
Largest Value in the list is : 98
Smallest Value in the list is : 3
second Largest value in the List is: 88
Second smallest value in the List is: 9
Number of Even Number in the List is : 12
>>> == RESTART: D:\old\r19 lab-python\12.py =======
List Elements are: [31, 56, 77, 32, 47, 85, 17, 61, 86, 50, 86, 85, 96, 14, 37, 64, 75, 11, 22, 68]
The Average of the Elements in the list is= 55.0
Largest Value in the list is : 96
Smallest Value in the list is : 11
second Largest value in the List is: 86
Second smallest value in the List is: 14
Number of Even Number in the List is : 10
No comments:
Post a Comment