-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathListMaker.py
150 lines (108 loc) · 3.87 KB
/
ListMaker.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
"""
This module creates lists that will be used to analyze the performance of the searching and sorting algorithms.
Student Name: Michael Fourie
Student Number: 20102203
"""
import random
def unorderdIntegers(minValue, maxValue, length):
"""
This function produces a list of random integers unordered.
Input: the range of what the integers should be in aswell as length of list
Output: list of unordered integers
"""
# Empty list to hold the values
aList = []
# For loop to append each random value to the list
for i in range(0, length):
aList.append(random.randint(minValue, maxValue))
# return list
return aList
def orderdIntegersAscending(minValue, maxValue, length):
"""
This function produces a list of random integers ordered from smallest to largest.
Input: the range of what the integers should be in aswell as length of list
Output: list of ordered integers
"""
# Empty list to hold the values
aList = []
# For loop to append each random value to the list
for i in range(0, length):
aList.append(random.randint(minValue, maxValue))
# sort list
aList.sort()
# return list
return aList
def orderdIntegersDescending(minValue, maxValue, length):
"""
This function produces a list of random integers ordered from largest to smalled.
Input: the range of what the integers should be in aswell as length of list
Output: list of ordered integers
"""
# Empty list to hold the values
aList = []
# For loop to append each random value to the list
for i in range(0, length):
aList.append(random.randint(minValue, maxValue))
# sort list
aList.sort(reverse=True)
# return list
return aList
def unorderdFloats(length):
"""
This function produces a list of unordered floats between 0.0 and 1.0
Input: length of list
Output: unordered list
"""
# empty list to hold values
aList = []
# for loop to append values to list
for i in range(length):
aList.append(random.random())
# rerns the list
return aList
def ascendingFloats(length):
"""
This function produces a list of ascending floats between 0.0 and 1.0
Input: length of list
Output: unordered list
"""
# empty list to hold values
aList = []
# for loop to append values to list
for i in range(length):
aList.append(random.random())
# sort the list
aList.sort()
# rerns the list
return aList
def descendingFloats(length):
"""
This function produces a list of Descending floats between 0.0 and 1.0
Input: length of list
Output: unordered list
"""
# empty list to hold values
aList = []
# for loop to append values to list
for i in range(length):
aList.append(random.random())
# sort the list
aList.sort(reverse=True)
# rerns the list
return aList
if __name__ == '__main__':
print(unorderdIntegers(-1000, 1000, 25),
'\nshould be a list of random integers, unsorted, 25 units long, range from -1000 to 1000')
print('')
print(orderdIntegersAscending(-1000, 1000, 25),
'\nshould be a list of random integers, sorted and ascending, 25 units long, range from -1000 to 1000')
print('')
print(orderdIntegersDescending(-1000, 1000, 25),
'\nshould be a list of random integers, sorted and descending, 25 units long, range from -1000 to 1000')
print('')
print(unorderdFloats(25), '\nshould be a list of random floats, unsorted.')
print('')
print(descendingFloats(25), '\nshould be a list of random floats, descending.')
print('')
print(ascendingFloats(25), '\nshould be a list of random floats, ascending.')
print('')