I have been taking a Python course. Be that as it may, one of the tasks 5.2 on week 7 stood out enough to be noticed.
The goal is to cause the user to enter a few numbers and enter done when he entered all the numbers he needed. From that point onward, the output should be the greatest number and most modest number he entered.
Here is the issue. In the event that I enter a negative number, it isn't shown. Suppose I enter: 32, 55,10, - 2 76. The output should be 76 and - 2. However, what truly happens is that 76 and 10 are printed out.
Do you guys know why this occurs?
Here is the code.
largest = None
smallest = None
while True:
try:
num = input("Enter a number: ")
if num == "done":
break
print (num)
num = int(num)
for number in range(num):
if largest is None or largest < num:
largest = num
continue
elif smallest is None or smallest > num:
smallest = num
except ValueError:
print("Please, enter only numbers.")
print ("Maximum", largest)
print ("Minimum", smallest)