-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathSelectionSort.py
More file actions
57 lines (44 loc) · 1.19 KB
/
SelectionSort.py
File metadata and controls
57 lines (44 loc) · 1.19 KB
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
"""
File: SelectionSort.py
Original Author: Br. Burton, designed to be completed by others.
Sorts a list of numbers.
"""
def sort(numbers):
"""
Fill in this method to sort the list of numbers
"""
for sort_position in range(len(numbers) - 1, 0, -1):
max_position = 0
for swap_position in range(sort_position + 1):
if numbers[swap_position] > numbers[max_position]:
max_position = swap_position
numbers[sort_position], numbers[max_position] = numbers[max_position], numbers[sort_position]
def prompt_for_numbers():
"""
Prompts the user for a list of numbers and returns it.
:return: The list of numbers.
"""
numbers = []
print("Enter a series of numbers, with -1 to quit")
num = 0
while num != -1:
num = int(input())
if num != -1:
numbers.append(num)
return numbers
def display(numbers):
"""
Displays the numbers in the list
"""
print("The list is:")
for num in numbers:
print(num)
def main():
"""
Tests the sorting process
"""
numbers = prompt_for_numbers()
sort(numbers)
display(numbers)
if __name__ == "__main__":
main()