-
Notifications
You must be signed in to change notification settings - Fork 0
/
list_operations.py
47 lines (45 loc) · 1.33 KB
/
list_operations.py
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
38
39
40
41
42
43
44
45
46
47
import random
while True:
numlist = []
listavg = 0
count = int(input("How big is the list: "))
while count > 0:
randint = random.randint(10, 100)
numlist.append(randint)
count = count - 1
print("The list contains: ")
for i in numlist:
print(i, end="\t")
print()
print("The first and last elements are:", numlist[0], numlist[-1])
print("The largest value is: ", max(numlist))
for i in numlist:
listavg = listavg + i
average = listavg / len(numlist)
print("The average of the elements is: ", average)
print("List elements in descending order are: ")
numlist.sort(reverse = True)
for i in numlist:
print(i, end="\t")
print()
fivelist = [i + 5 for i in numlist]
print("The contents of the list after adding 5 to each element:")
for i in fivelist:
print(i, end="\t")
print()
print("The contents of the list after adding 1, 2, and 5:")
numlist.insert(0, 1)
numlist.insert(3, 5)
numlist.append(2)
for i in numlist:
print(i, end="\t")
print()
del numlist[0:4]
numlist.pop(-1)
print("List after removing the first 4 and last elements:")
for i in numlist:
print(i, end="\t")
print()
goAgain = input("Do is again? (yes or no): ")
if goAgain[0] is "n":
break