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. Rays 11.1K posts
- 2. Merry Christmas 168K posts
- 3. Shane Baz N/A
- 4. Tucker 156K posts
- 5. Brandon Lowe 1,718 posts
- 6. Western Michigan 1,569 posts
- 7. Kennesaw State 1,648 posts
- 8. #FanCashDropPromotion 2,818 posts
- 9. Strahm 3,230 posts
- 10. Burrows 1,829 posts
- 11. Mangum N/A
- 12. #FursuitFriday 13.2K posts
- 13. #NXXT_NEWS 1,184 posts
- 14. NextNRG 3,511 posts
- 15. Brito 2,847 posts
- 16. #FridayVibes 4,904 posts
- 17. Ben Shapiro 86.4K posts
- 18. Happy Holidays 49K posts
- 19. Comets 2,170 posts
- 20. Sought 15.5K posts
Something went wrong.
Something went wrong.