-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlibrary_IGCSE.py
64 lines (57 loc) · 1.7 KB
/
library_IGCSE.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
def counting(array):
global counter
counter = 0
for i in array:
counter+=1
print(f"The array has {counter} elements.")
return counter
def totalling(array):
global total
total = 0
for i in array:
total+=i
print(f"The total of the elements array is {total}.")
return total
def linearsearch(array):
value=float(input("What number do you want to search for in your array?"))
found=False
index=0
while not found and index<len(array):
if array[index]==value:
found=True
else:
index+=1
if found == True:
print(f"Your number has been found at position {index}")
else:
print("Your value has not been found in the array.")
def bubblesort(array):
lengtharray = len(array)
for i in range(lengtharray):
swapped = False
for j in range(0, lengtharray-i-1):
if array[j]>array[j+1]:
array[j], array[j+1] = array[j+1], array[j]
swapped = True
print(array)
if not swapped:
break
def minimum(array):
minimum=array[0]
for i in array[1:]:
if i < minimum :
minimum=i
print(minimum)
print(f"The minimum value from {array} is {minimum}")
def maximum(array):
maximum=array[0]
for i in array[1:]:
if i > maximum :
maximum=i
print(maximum)
print(f"The maximum value from {array} is {maximum}")
def average(array):
totalling(array)
counting(array)
average=total/counter
print(f"The averega of this array {array} is {average}")