Got Homework?
Connect with other students for help. It's a free community.
Here's the question you clicked on:
 0 viewing
he66666
Group Title
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
 2 years ago
he66666 Group Title
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
 2 years ago

This Question is Closed

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

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

bmp Group TitleBest ResponseYou've already chosen the best response.1
x 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.
 2 years ago

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

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

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

he66666 Group TitleBest ResponseYou've already chosen the best response.0
Thanks so much guys! :D
 2 years ago
See more questions >>>
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.