Questions about python:
1. If x is a list of integers, what would the function be if you have to return true if all the elements in x are 0 for the function x(y)?
I got "return int(0) in hits_list" but it doesn't make sense because it can include other values with 0 in the list..
2. f(x, y):
"""(integer, integer) -> boolean
Return True if x and y are between 0 (included) and 8 (non-included) and false otherwise."""
I don't get how to do this when there are two variables, x and y, since I want to write a function with an if-statement..
Can someone please help me?
At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga.
Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus.
Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.
The 2. you can do something like:
if (x < 8 or x >= 0) and (y < 8 or y >= 0): return True
else: return False
Note: I think the parenthesis are not needed, but just for clarity's sake.
The 1. I didn't quite understand. Given a list of integers, it should return True if all are 0 and False otherwise?
If so, do it like:
for i in x:
if i != 0:
I agree, the first question is a little difficult to understand.
@bmp, good answer. I think you meant to put "and" instead of "or" in your two comparisons. And I believe you do require parenthesis when you've got multiple comparisons as well.
x should be either >= 0 or < 8 and y should be either >= 0 or < 8 simultaneously, right? It's like (Ax|Bx) & (Ay|By), where A, B are the relational operations for x, y respectively. Anyway, if I have committed a mistake, sorry. My bad.
Not the answer you are looking for? Search for more explanations.
If it's either >= 0 or < 8, that would include everything; all from 0 up to infinity or 8 down in the opposite direction. I think what he's looking for are the numbers between 0 and 8. Therefore, >= 0 and < 8. Right?
Oh, yeah. My bad. I didn't realize the basic from the or operator. I am sorry if I caused some confusion. keketsu is right, it's >= 0 and < 8. :-) Thanks for catching that.
No problem. You were very quick on the answer. That kind of error is just like missing a comma.