Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question 5: zero sum is "possible" ? #39

Open
mishgu opened this issue Jan 31, 2018 · 3 comments
Open

Question 5: zero sum is "possible" ? #39

mishgu opened this issue Jan 31, 2018 · 3 comments

Comments

@mishgu
Copy link

mishgu commented Jan 31, 2018

So we have that question

>>> x, y = ???
>>> sum(0 * x, y) == y
False

if x equal one of

[], '' or ()

and

y = float('nan')

that snippet is possible.
For ex:

>>> x, y = '', float('nan')
>>> sum(0 * x, y) == y
False

Please correct me if I'm wrong.

@pschwede
Copy link

pschwede commented Mar 8, 2018

Let's break it down a bit:

0*[] means [], because 2*[x] means [x,x]. If you sum([], float("nan")), you get the sum of all numbers in [] plus your starting value float("nan"), which results in nan. However if you try float("nan") == float("nan") you always get False. That's I think because == either compares two numbers or two objects with each other (despite being typed float). Now, because float("nan") yields not a number, it cannot be equal to any number, not even to itself:

>>> y=float("nan")
>>> y==y
False

In the end, why did you use == on not a number in the first place? I don't see where this is a pywat.

@mishgu
Copy link
Author

mishgu commented Mar 9, 2018

When we look at Question 5: zero sum the answer tells "No. This snippet is impossible."
So if use my example, that snippet is possible and can I use that example as correct answer

@cosmologicon
Copy link
Owner

Thanks for the report. But you can't use NaNs. Those are considered "trick" answers for the purpose of the quiz, because NaNs have edge cases that have nothing to do with Python, and it would be unfair to expect people to know them all. This is the first bullet point under the "Details and Scope" section. If you think there's a clearer way to say this, I'm open to it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants