Conditional Statements
Conditional Statements
2. Consider the following code. When prompted for input, the user enters the string monday.
What is the output?
day = input("What day is it? ")
day = day.lower()
if day != ’saturday’ and day != ’sunday’:
print("Yep.")
else:
print("Nope.")
print(wanted)
(a) True
(b) False
(c) None of the above.
(d) This code produces an error.
a = 5
b = -10
if a < b or a < 0 and b < 0:
print("Yes, it’s true.")
else:
print("No, it’s false.")
(a) True
(b) False
11.10. REVIEW QUESTIONS 293
print(is_lower("t"))
(a) True
(b) False
(c) None
(d) This code produces an error
(a) True
(b) False
(c) None
(d) This code produces an error.
data1 = [5, 3, 2, 2, 0]
data2 = [5, 2, 3, 2, 0]
print(monotonic(data1), monotonic(data2))
data = [5, 3, 2, 2, 0]
swapper(data)
print(data)
(a) True
(b) False
(c) None of the above.
(d) This code produces an error.
(a) True
(b) False
(c) 0
(d) 10
(a) 4
(b) 1
(c) 0
(d) -1
(e) None of the above.
(a) 4
(b) 1
(c) 0
(d) -1
(e) None of the above.
19. What is the value returned by the function func1() when it is called in the following code?
def func1(xlist):
for x in xlist:
if x < 0:
return False
return True
(a) True
(b) False
(c) None of the above.
(d) This code produces an error.
20. What is the value returned by the function func2() when it is called in the following code?
def func2(xlist):
for i in range(len(xlist) - 1):
if xlist[i] + xlist[i + 1] == 0:
return True
return False
(a) True
(b) False
(c) None of the above.
(d) This code produces an error.