why when i pass 0 to this function, i get error? `square = lambda n: 2**(n-1) if n in range(1,65) else valueerror("between 1 and 64 pls")` in python

The reason you're getting an error when passing 0 to this function is because the range function in Python starts from 0 by default. Since the valid range for n is from 1 to 64, passing 0 to the function will cause the n in range(1, 65) condition to evaluate to False, triggering the else statement which raises the ValueError.

To fix this, you can update the range to start from 1 by replacing range(1, 65) with range(1, 65). Here's the corrected version of the function:

main.py
square = lambda n: 2**(n-1) if n in range(1, 65) else ValueError("between 1 and 64 pls")
89 chars
2 lines

Now, when you pass 0 to the function, it will raise a ValueError with the specified message.

gistlibby LogSnag