Question: 2 . Can a variable declared within an if statement be accessed outside of that if statement? A . Yes, it can. B . No

2. Can a variable declared within an if statement be accessed outside of that if statement?
A. Yes, it can.
B. No, it cannot.
C. It depends on whether the declaration executes.
D. Only if the variable is defined as global.
3. What is the result of the logical operation True and False?
A. True B. False C. None D. Error
4. Which logical operator in Python returns True if at least one of the operands is
True?
A. and B. or C. not D. is
5. When would you typically use a conditional expression in Python?
A. When you need to execute a block of code repeatedly.
B. When you need to iterate over a known sequence of elements.
C. When you need to assign a value based on a condition.
D. When you want to handle errors and exceptions.
6. What happens if none of the conditions in an if-elif-else block are met?
A. The program terminates.
B. The block of code associated with the else statement is executed.
C. The program moves to the next line of code outside the if-elif-else block.
D. An error is raised.
7. When would you typically use an elif statement instead of multiple if statements?
A. When you want to provide a default block of code to execute when none of the
previous conditions are met.
B. When you have multiple conditions to check, but only one of them should
trigger.
C. When you need to execute a block of code repeatedly.
D. When you want to handle specific cases within a larger set of conditions.
CS303E Week 4 Worksheet: Selections 3
8. Consider the expression x >=0 or y <10. If we assume x is equal to 10, and y
is equal to 5, then... (hint: think of short-circuit evaluation)
A. Python will evaluate both conditions in left-right order to determine whether
the expression is True.
B. Python will evaluate both conditions in right-left order to determine whether
the expression is True.
C. Python will evaluate only the second condition, y <10.
D. Python will evaluate only the first condition, x >=0.
9. Which of the following statements is true?
A.(x >=5 and x <15) is the same as (5<= x <15)
B.(y >0 or y <-10) is the same as y >0 and y <-10
C.(x >0 or x <-5 and y <0) is the same as
((x >0 or x <-5) and y <0)
D. A and C are both true
10. Which of the following is equivalent to the expression
(p + q > r) and (s - t <= u)?
A.(p + q > r) and not (s - t >= u)
B. not (p + q < r) and (s - t <= u)
C.(p - q <= r) and (t - s > u)
D. not ((p + q <= r) or (s - t > u))
11. What does the expression 5+10*2//3-4 evaluate to?
A.6 B.7 C.8 D.9

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Finance Questions!