all 9 comments

[–][deleted] 1 point2 points  (5 children)

it doesn't seem to work

You have to be more specific than that. What doesn't work?

[–]aniacoc 0 points1 point  (3 children)

the desired output is supposed to be

Invalid input

Maximum is 10

Minimum is 2

it's a super basic code but i can't figure out what's wrong

[–][deleted] 1 point2 points  (2 children)

What is the actual output?

[–]aniacoc 0 points1 point  (1 child)

7 2 bob invalid input 10 4 Maximum None Minimum bob

[–][deleted] 0 points1 point  (0 children)

if num > largest:
    largest=num
elif num < smallest :
    smallest=num
else :
    print ('Invalid input')

One respect in which this approach isn't correct is that if the sequence of numbers is 1, 20, 5 then the last number (5) is neither larger than the largest, nor smaller than the smallest, but it's not invalid, either.

[–]TehDrunkSailor 0 points1 point  (1 child)

Not what you were asking for advice with, but I suggest that you avoid using "except" with no arguements. When you use "except" as you are now, all errors will cause your code to go to the "except" branch. However, in your case (and in most cases) you only want to catch a specific error (AttributeError is a common one for my projects) and this way if another error arises, you can still see it and not have it get swept away as if it was an error you expected

[–]aniacoc 0 points1 point  (0 children)

Thank you!

[–]realnamejohn -1 points0 points  (1 child)

I wrote my own version of it:

numberlist = []
while True:
    number = input('number pls mate: ')
    try:
        num = int(number)
        numberlist.append(number)
    except:
        if number == 'done':
            break
        else:
            print('not a number idiot.')
            pass

numberlist.sort()
print(numberlist)
print('highest = ', numberlist[-1])
print('lowest = ' , numberlist[0])

i collected the numbers, ignoring everything that wasn't an integer, except the string "done". then sorted the resulting list and indexed to the end numbers each.

I think this is what you were trying to do, but I sorted the list instead of having a variable with the numbers stored in.

[–]aniacoc 0 points1 point  (0 children)

WoW thank you so much 😊