click below
click below
Normal Size Small Size show me how
Python Ch. 2 Review
Review of Python Chapter 2
Question | Answer |
---|---|
2-1. What are the values for Boolean in Python? a. True, False b. TRUE, FALSE c. true, false d. Yes, No | a. True, False |
2-2. How many comparison operators are there in Python? | Six: ==, !=, >, >=, <, <= |
2-3. What is the difference between = and ==? | = is the assignment operator. It is used to assign a value to a variable. == is the equal comparison operator. It is used to compare if 2 values are equal. |
2-4. What are the logical operators in Python? | and, or, not |
2-5. Multiple Boolean expressions can be combined by using a ________ operator to create compound expressions. | logical |
2-6. When using the _________ operator, one or both sub-expressions must be true for the final expression to be true. | or |
2-7. When using the _________ operator, both sub-expressions must be true for the final expression to be true. | and |
2-8. Which of the following is the correct if clause to determine whether y is in the range 10 through 50? a. if 10 < y 50 b. if 10 < y or y > 50 c. if 10 > y and y < 50 d. if y > 10 and y < 50 e. if y > 10 or y < 50 | d. if y > 10 and y < 50 |
2-9. Is there another way to accomplish this comparison? if x > 10 and x < 20: | Yes. by using: if 10 < x < 20: |
2-10. What is the result of the following Boolean expression, if x is 5, y is 3, and z is 8? x < y or z > x | True |
2-11. What is the result of the following Boolean expression, if x is 5, y is 3, and z is 8? x < y and z > x | False |
2-12. What is the result of the following Boolean expression, if x is 5, y is 3, and z is 8? not (x < y or z > x) and y < z | False |
2-13. Which of the following is the correct if clause to use to determine whether choice is other than 10? a. if choice != 10: b. if choice != 10 c. if choice <> 10: d. if choice <> 10 e. None of the above | a. if choice != 10: |
2-14. A(n) ____________ statement will execute one block of statements if its condition is true, or another block if its condition is false. | if-else |
2-15. What Python keyword allows us to check for more conditions in case the first block was false? | The elif keyword (if-elif...else) |
2-16. The logical ____ operator reverses the truth of a Boolean expression. | not |
2-17. What will this code print? flag = False if not flag: print ('Line 1 will be printed') else: print ('Line 2 will be printed') | Line 1 will be printed |
2-18. What will this code print? x = 10 y = 15 if x%3==0 and y%3==0: print ('Line 1 will be printed') elif x%3==0 or y%3==0: print ('Line 2 will be printed') else: print ('Line 3 will be printed') | Line 2 will be printed |