In: Computer Science
1.
Which of the following is a method that can be called on a list?
Group of answer choices
split()
lower()
strip()
All of the above methods can be called on a list
None of the above
2.
Which one of these correctly reads a value from the keyboard into variable x?
Group of answer choices
input(x)
readline(x)
x = input()
x = readline()
3.
What happens if you run the following code?
x = input("Enter a value: ") if x > 50: print("You have entered a value over 50.")
Group of answer choices
It prints “You have entered a value over 50.” if the user enters 52
It prints whatever the user enters
It does not run because the type of the value x is different than that of 50
It does not run because the value of x is not set when the program starts
4.
Which one of the following statements is NOT true?
Group of answer choices
While loops always increment the iterating variable automatically in each iteration.
A while loop is best for situations when we do not know how many times the statements in the body of the loop need to be executed.
The statements in the body of a for loop must be indented.
Variables initialized in a function have local scope.
A while loop can iterate infinitely (i.e., an infinite loop)
5.
Suppose s is a variable that has been assigned a string, but you don't know exactly what that string is. Consider the expression:
s.split().strip()
Group of answer choices
It evaluates to a list where elements are strings with no spaces at all
It evaluates to a string with no leading and no trailing spaces
It produces an error always
It produces an error except when s is the empty string
None of the above
6.
If the variable lst is assigned the list ['apple', 'orange', 'pear', 'plum'], which one of the following statements will cause an error when run?
Group of answer choices
print(lst[-1])
print(lst[0])
print(lst[3])
print(lst[4])
7.
What should ??? be replaced by to make the printed value of n as big as possible?
lst = ["gold", "red", "green", "gray1", "gamboge", "yellow", "teal"] n = 0 for c in lst: if c[1] == ???: n = n + 1 print(n)
Group of answer choices
'a'
'e'
'g'
'r'
8.
Select all the Boolean expressions:
Group of answer choices
8 + 1 = 4
6 == 2 + 3
4 + 2 == 8
‘dog’ == ‘doggy’
True
print("False")
12 > 14
'cat' < 'dog' and 2 > 3
5 = 2 + 4
9.
In a Python program, functions must be called in the same order as they are defined in the ".py" file.
Group of answer choices
True
False
1. answer: None of the Above
2. answer: x = input()
3.answer: It does not run because the type of the value x is different than that of 50
4. answer:
5. answer: It produces an error always
6. answer: print(lst[4])
7. answer: 'e'
8.
6 == 2 + 3
4 + 2 == 8
'dog' == 'doggy'
True
12 > 14
'cat' < 'dog' and 2 > 3
9. answer: FALSE