-2

enter image description here

Is divisor a built-in variable that checks if the input is zero or not?

I googled but not idea at all. I knew something called zerodivisionerror but it seems like it is not linked with this program? Therefore, I am flummoxed by this function. Or did I miss understood something? Thank you for your help.

Abhijit Sarkar
  • 21,927
  • 20
  • 110
  • 219
  • 4
    Please don't post code or output as images. – Mark Ransom Oct 17 '22 at 16:53
  • it is generally good practise to post your code as text in the question rather than as a screenshot as it makes it easier for others to reproduce your code :D – Cornelius-Figgle Oct 17 '22 at 16:54
  • To cite the documentation of [Boolean operations](https://docs.python.org/3.10/reference/expressions.html#boolean-operations): "In the context of Boolean operations, and also when expressions are used by control flow statements, the following values are interpreted as false: `False`, `None`, numeric zero of all types, and empty strings and containers (including strings, tuples, lists, dictionaries, sets and frozensets). All other values are interpreted as true.". – Matthias Oct 17 '22 at 17:41
  • Does this answer your question? [What is Truthy and Falsy? How is it different from True and False?](https://stackoverflow.com/questions/39983695/what-is-truthy-and-falsy-how-is-it-different-from-true-and-false) – Sören Oct 17 '22 at 18:22

1 Answers1

1

There is nothing special about divisor, it's just the name that was chosen for a parameter by whoever wrote the divide function.

The key to the function is in the if not divisor: test. Zero is considered False, so not divisor is True if the number is zero.

Try searching for Truthy/Falsy rules in Python.

Mark Ransom
  • 299,747
  • 42
  • 398
  • 622