3 ms·
FuzzBuzz and the Art of Programming
- hawkice 11y agoObviously a minor point, but if x: return True else: return False is weirdo-code. Just use return x, maybe cast to bool if you need to.
- cool_guy_this 11y agoreturn x is way more pythonic, because it's much clearer and any non-boolean value can be used in boolean contexts as well.
- coldtea 11y agoYou can also "return not not x" which turns the value into its boolean true/false equivalent ("!!x" in a C-like language). Or "return bool(x)" to make this more explicit. Those would be handy e.g. if the code that uses your result behaves differently 0 and False.
- wnoise 11y agoNo itertools.cycle()?
- spc476 11y agoHis recursive function didn't remove Boolean checks, it just hid it in the runtime system. Better---have a function just print one out of the sequence. A second function to call the first one ten times. Then a third function to call the second one ten times. No loops, no (hidden) Boolean checks, no math, no modulus, no recursion.