A community for students. Sign up today!
Here's the question you clicked on:
 0 viewing
 2 years ago
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 (nonincluded) 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 ifstatement..
Can someone please help me?
 2 years ago
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 (nonincluded) 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 ifstatement.. Can someone please help me?

This Question is Closed

bmp
 2 years ago
Best ResponseYou've already chosen the best response.1The 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: return False return True

keketsu
 2 years ago
Best ResponseYou've already chosen the best response.3I 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.

bmp
 2 years ago
Best ResponseYou've already chosen the best response.1x should be either >= 0 or < 8 and y should be either >= 0 or < 8 simultaneously, right? It's like (AxBx) & (AyBy), where A, B are the relational operations for x, y respectively. Anyway, if I have committed a mistake, sorry. My bad.

keketsu
 2 years ago
Best ResponseYou've already chosen the best response.3If 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?

bmp
 2 years ago
Best ResponseYou've already chosen the best response.1Oh, 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.

keketsu
 2 years ago
Best ResponseYou've already chosen the best response.3No problem. You were very quick on the answer. That kind of error is just like missing a comma.

he66666
 2 years ago
Best ResponseYou've already chosen the best response.0Thanks so much guys! :D
Ask your own question
Ask a QuestionFind more explanations on OpenStudy
Your question is ready. Sign up for free to start getting answers.
spraguer
(Moderator)
5
→ View Detailed Profile
is replying to Can someone tell me what button the professor is hitting...
23
 Teamwork 19 Teammate
 Problem Solving 19 Hero
 Engagement 19 Mad Hatter
 You have blocked this person.
 ✔ You're a fan Checking fan status...
Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.