Bonjour,

je dois écrire un code pour cette question :
Write a program that repeatedly prompts a user for integer numbers until the user enters 'done'. Once 'done' is entered, print out the largest and smallest of the numbers. If the user enters anything other than a valid number catch it with a try/except and put out an appropriate message and ignore the number. Enter 7, 2, bob, 10, and 4 and match the output below.
La réponse que je dois reproduire est la suivante:

Invalid input
Maximum is 10
Minimum is 2
et voici mon code:

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
largest = None
smallest = None
 
print("Invalid input")
while True:
    num = input("Enter a number: ")
    if num == "done":
       break
    if smallest is None:
           smallest = num
 
    elif num < smallest : 
          smallest = num
 
    if largest is None:
           largest = num
 
    elif num > largest:
           num = largest
 
 
print("Maximum is", largest) 
print("Minimum is", smallest)
Pouvez-vous me dire où est mon erreur. Je commence en langage Python et vos lumières vont m'aider?

Merci!

Daniel