It tests whether the input string is a palindrome: reversing the characters leaves the string unchanged. Comparisons are case-sensitive and include spaces and punctuation. For example, mystery1("level") returns True, whereas mystery1("lever") returns False.
It performs a trial division test for a prime number. An integer below is rejected; otherwise the function searches for a divisor from through . A composite number has a prime factor no larger than its square root, so finding no such divisor proves primality. For example, mystery2(97) returns True, while mystery2(91) returns False, since .
This describes the intended mathematical test. For extremely large integers, the floating-point computation n**0.5 can round or overflow; an implementation intended for arbitrary-size integers should use an exact integer square root.
It filters the first list by membership in the second list, retaining the order and all repetitions of qualifying entries in the first list. For example, mystery3([3, 1, 3, 2], [3, 4]) returns [3, 3]. Thus it is related to set intersection, but its result is a list and does not discard repeated elements.
With its default argument and a nonnegative integer input, it prints the decimal digits of in order, one per line. For example, mystery4(407) prints 4, then 0, then 7. Integer division removes the final digit, recursion handles the preceding digits, and the remainder gives the final digit. The function returns None.
There is a subtlety for a nondefault base: the recursive call omits m, so it resets to . For and , the actual output is the decimal digits of , followed by the remainder . For example, mystery4(13, 2) prints 6, then 1, rather than the binary digits of . Passing m on to the recursive call would give a consistent base- positional notation. The interpretation as digits assumes and ; arbitrary integer arguments need not satisfy those conditions.

Articles by others on the same topic (0)

There are currently no matching articles.