Quantcast

A community for students. Sign up today!

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

he66666

  • 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 (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?

  • This Question is Closed
  1. bmp
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 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. keketsu
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 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.

  3. bmp
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 1

    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.

  4. keketsu
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 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?

  5. bmp
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 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.

  6. keketsu
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 3

    No problem. You were very quick on the answer. That kind of error is just like missing a comma.

  7. he66666
    • 2 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    Thanks so much guys! :D

  8. Not the answer you are looking for?
    Search for more explanations.

    Search OpenStudy
    • Attachments:

Ask your own question

Ask a Question
Find 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
  • 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.

This is the testimonial you wrote.
You haven't written a testimonial for Owlfred.