-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheau12.py
47 lines (36 loc) · 1.07 KB
/
eau12.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 sys
# Fonctions utilisées:
def my_bubble_sort(array):
array = list(map(int, array))
n = len(array)
for i in range(n-1):
for j in range(n-i-1):
if array[j] > array[j+1]:
array[j], array[j+1] = array[j+1], array[j]
return " ".join(map(str, array))
# Gestion d'erreurs :
def is_valid_length(arguments):
if len(arguments) < 2:
print("Erreur : Merci d'indiquer au moins deux arguments")
return False
return True
def is_valid_arguments(arguments):
for argument in arguments:
if not argument.isdigit():
print("Erreur : Merci d'indiquer au moins deux arguments qui sont des nombres positifs")
return False
return True
# Récupération de données :
def get_arguments():
arguments = sys.argv[1:]
return arguments
# Résolution :
def display():
arguments = get_arguments()
if not is_valid_length(arguments):
return
if not is_valid_arguments(arguments):
return
print(my_bubble_sort(arguments))
# Affichage :
display()