Arithmetic operations on Bools?
Answer: B. False Solution: Let's go checking the if-condition, which is (3>2) > 1 Now remember that no matter what, attack the parenthesis first. So we solve (3>2), ie, True Expression simplifies to True > 1 It's a bit of a fix now. Because how to compare a bool with int? +
Not very often, but it can be applied. For example, you have a list like so li = [5, 7, 3, 2, 9] You want to count how many items are >5. You could use sum(x>5 for x in li) This works by creating a bool (x>5). If True, adds 1. Else adds 0. Effectively counting Trues. +
Another use is for "skipping terms" in sums by taking product with bools, like so interest_rate = general_interest_rate + (is_senior_citizen * extra_rate_for_senior_citizen) if is_senior_citizen is True, the value becomes the sum of 2 terms. Otherwise it's only the first term.
United States 趨勢
- 1. Good Sunday 60.2K posts
- 2. Happy Winter Solstice 6,598 posts
- 3. And Mary 27.6K posts
- 4. Bears 144K posts
- 5. Packers 97.5K posts
- 6. #sundayvibes 3,741 posts
- 7. #FirstDayOfWinter N/A
- 8. Happy Solstice 8,125 posts
- 9. Caleb 85.9K posts
- 10. Snowball 11.9K posts
- 11. Malik Willis 15.8K posts
- 12. DJ Moore 30.3K posts
- 13. Yule 6,121 posts
- 14. Ben Johnson 10.7K posts
- 15. Green Bay 14.1K posts
- 16. Doubs 9,336 posts
- 17. #BearDown 4,823 posts
- 18. Nixon 13.1K posts
- 19. Tulsi 80.2K posts
- 20. Mustard 18.2K posts
Something went wrong.
Something went wrong.