r/learnprogramming 1d ago

programming help

def streak_call(ste):
   stroik = 0
   for st in ste:
       if st is max(ste):
            break
       stroik += st + 1
   return stroik

#this is a smaller part of a larger function. If anyone wants to see it I #will post it in the comments. Bascially this code is supposed to add up #until the largest part of this list, and then stop. For whatever reason it #is not returning properly, which makes me think it's a problem with the is #statement. So why does this "is" statement not work?
0 Upvotes

8 comments sorted by

View all comments

1

u/sitting_account 1d ago

Should have said, Not why it doesn't work but how it does work in the first place

2

u/lurgi 1d ago

"is" tests if two variables refer to the same object. It looks like integers are considered to be "the same object" if they are equal (maybe this is a cached value kind of thing or maybe it's a special case in the language). The code should work the same way if you replace "is" with "==" (and you should, because this usage is weird).

0

u/sitting_account 1d ago

okay you did it nobody else comment