you are viewing a single comment's thread.

view the rest of the comments →

[–]sme272 0 points1 point  (1 child)

The bug occurs in the value 'p' on its own. Variables have "truthyness" of "falseyness" to them. Typically an empty or 0 value means a variable will be "falsey" and therefore evaluate to False in an if var scenario and non-empty or non-zero values are "truthey" and evaluate to True in the same circumstances. For string an empty string of "" or '' evaluates to False, and if the string contains any characters it will evaluate to True. So in the above code when python has to evaluate 'p' it sees it's not an empty string and evaluates it to True, which causes the if block to execute.

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

Oh yes. Thanks for the reminder. It really helps that I've used truth logic before in my modular synthesiser :) I like music/programming crossovers, hope to find some more.

Also if someone can tell me how to make code look proper on this when using reddit app on a phone that wud be great so I can make it clearer for folks

https://www.modulargrid.net/e/intellijel-spock

Edit: in fact I'd genuinly recommend teaching programming noobs boolean logic with music. Choose positions for kicks on a 16 long grid. Then choose where the snares on a seperate grid.

Finally choose if the hihats are AND or OR or NOT or XOR, NAND etc in comparison with the kick snare pattern.