A community for students.
Here's the question you clicked on:
 0 viewing
he66666
 4 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?
he66666
 4 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

anonymous
 4 years ago
Best ResponseYou've already chosen the best response.0The 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

anonymous
 4 years ago
Best ResponseYou've already chosen the best response.0I 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.

anonymous
 4 years ago
Best ResponseYou've already chosen the best response.0x 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.

anonymous
 4 years ago
Best ResponseYou've already chosen the best response.0If 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?

anonymous
 4 years ago
Best ResponseYou've already chosen the best response.0Oh, 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.

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

he66666
 4 years ago
Best ResponseYou've already chosen the best response.0Thanks so much guys! :D
Ask your own question
Sign UpFind 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.