Open Lucas-C opened 8 years ago
f = 100 * -0.016462635 / -0.5487545 # observed on the field, in a real-world situation print 'float f:', f # 3.0 print 'int f:', int(f) # 2
It is normall behavior of float type (also in other languages with this type, like C):
>>> f = 100 * -0.016462635 / -0.5487545
>>> f
2.9999999999999996
>>> print f
3.0
>>> int(f)
2
int()
just truncates everything after a comma. Use round()
instead.
Agreed, but I actually shouted WAT?? on this one.
Nice. Some good finds here. That dictionary one is especially surprising. Looks like it also works with bool/int/floats that hash equal. I'm thinking of this one as a new quiz question:
>>> x, s = ???
>>> s.add(x)
>>> type(x) in map(type, s)
False
where one answer is x, s = 1, {True}
.
So far I've gone with wats that only use builtins. I haven't gone into the standard library yet, but I'm thinking about adding a separate section for that. The id
-related ones I'm guessing depend on the implementation, but there should be a place for that too. I'll keep this open in the meantime. Thanks!
Glad I could help :)
First: thanks for this list, and the amazingly difficult AND fun quiz !
Now, a few suggestions to add to your collection of gotchas:
And I found out about those last 3 myself: