-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path7_2.py
More file actions
37 lines (24 loc) · 662 Bytes
/
7_2.py
File metadata and controls
37 lines (24 loc) · 662 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
"""
2. 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 i in range(20):
L.append(random.randint(1,100))
print(L)
print('Avg:',sum(L)/len(L))
L.sort()
print('Smallest:',L[0])
print('Largest:',L[-1])
print('2nd Smallest:',L[1])
print('2nd Largest:',L[-2])
even = 0
for item in L:
if(item%2==0):
even += 1
print('Total Even items:',even)