






































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!







































What is Python's response to the command: type(0.123) a. <class 'float'> b. <class 'bool'> c. SyntaxError: invalid syntax d. <class 'int'> e. <class 'str'> Correct Answer a. <class 'float'> Consider the following text from a Python interpreter.
print(2 + 2) 4 What is the text ">>>" called? a. a function b. an operator c. a prompt d. a statement e. a value Correct Answer c. a prompt What does the following text indicate in a Python interpreter?>>>
a. A syntax error has occurred. b. One value is much greater than another. c. Shift a value to the right. d. The interpreter is ready for you to enter code. e. The emoji for "food chain". Correct Answer d. The interpreter is ready for you to enter code. Which one of the following Python expressions generates a syntax error? a. 8 ^ 2 b. 8 ** 2 c. 8 +- 2 d. 8 += 2 e. 8 - + 2 Correct Answer d. 8 += 2 Which one of the following Python expressions computes the total number of seconds in 21 minutes and 21 seconds? a. 21 + 21 b. 21 + 60 c. "21 minutes" + "21 seconds" d. 21 * 60 + 21 e. seconds = 21 + "21 minutes" Correct Answer d. 21 * 60
Which of the following is an invalid Python assignment statement? a. a = b = 123 b. '3' = 3 c. x = int("123") d. y = None e. z = "hi" * 10 Correct Answer b. '3' = 3 What is the output of the following statements? pi = float(3.14159) print (pi) a. 3 b. 3. c. 3. d. 0 Correct Answer c. 3. Programmers generally choose names for their variables that are meaningful and document what the variable is used for. Correct Answer True What output will the following Python statements produce?
print (2*3-1) a. 6 b. 5 c. 4 d. 3 Correct Answer b. 5
An expression is a combination of values, variables, and operators. If you type an expression on the command line, the interpreter evaluates it and displays the result. Correct Answer True What output will the following Python statement produce?
print ((1,000,000)) a. 1, b. 1,000, c. (1, 0, 0) d. Error invalid type Correct Answer c. (1, 0, 0) Using Python keywords for variable names will result in a
a. runtime error b. compile error c. syntax error d. semantic error Correct Answer c. syntax error What do we call the value provided to a function when the function is called (which is assigned to the corresponding parameter in the function)? a. argument b. return value c. method d. the special value None
c. 109. d. 109.0 Correct Answer b. 109 What output will the following python commands produce: x = 5 if x % 2 == 0: print (x) else: print (x, x%2) a. 5 b. 5 1 c. 2 d. 5 0 Correct Answer b. 5 1 What is the output of the following Python statements? pi = int(3.14159) print (pi) a. 3 b. 3. c. 3. d. 0 Correct Answer a. 3 What output will the following python commands produce: x= y= if x == y:
print (x, "and", y, "are equal") else: if x < y: print (x, "is less than", y) else: print (x, "is greater than", y) a. 1 and 2 are equal b. 1 is less than 2 c. 1 is greater than 2 d. 2 is greater than 1 Correct Answer b. 1 is less than 2 Functions allow the programmer to encapsulate and generalize sections of code. Correct Answer True What output will the following python command produce:
percentage = float ( 60 * 100) / 55 print (percentage) print ((1,000,000)) a. 1, b. 1,000, c. (1, 0, 0) d. Error invalid type Correct Answer c. (1, 0, 0) Using Python keywords for variable names will result in a ________________ a. runtime error b. compile error c. syntax error d. semantic error Correct Answer c. syntax error What do we call the value provided to a function when the function is called (which is assigned to the corresponding parameter in the function)? a. argument b. return value c. method d. the special value None c. 109. d. 109.0 Correct Answer b. 109 What output will the following python commands produce: x = 5 if x % 2 == 0: print (x) else: print (x, x%2) a. 5 b. 5 1 c. 2 d. 5 0 Correct Answer b. 5 1 What is the output of the following Python statements? pi = int(3.14159) print (pi) a. 3 b. 3. c. 3. d. 0 Correct Answer a. 3 What output will the following python commands produce: x= y= if x == y: print (x, "and", y, "are equal") else: if x < y: print (x, "is less than", y) else: print (x, "is greater than", y) a. 1 and 2 are equal b. 1 is less than 2 c. 1 is greater than 2 d. 2 is greater than 1 Correct Answer b. 1 is less than 2 Functions allow the programmer to encapsulate and generalize sections of code. Correct Answer True What output will the following python command produce: >>> percentage = float ( 60 * 100) / 55 >>> print (percentage) a. percentage b. 109 c. 109. d. 109.0 Correct Answer c. 109. If you assign the result a void function to a variable in Python, you get: a. an empty string b. the value - 1 c. the value 0
a. a histogram b. an inverted dictionary c. a list of tuples d. a lookup e. a reverse lookup Correct Answer e. a reverse lookup What will the contents of mylist be after the following Python code has been executed?
mylist = [1, 4, 2, 3] mylist.append(5) a. [1, 4, 2, 3, 5] b. [5, 1, 4, 2, 3] c. [null] d. [1, 4, 2, 3] Correct Answer a. [1, 4, 2, 3, 5] Python tuples are immutable. Correct Answer True If you use a Python dictionary in a for statement, it traverses the _____ of the dictionary. a. values and keys b. indices c. keys and values d. values e. keys Correct Answer e. keys What is the output of the Python code below?
my_tup = (3, 2, 1, 2) print(tuple(sorted(my_tup))) a. (1, 2, 3) b. {1, 2, 2, 3} c. (1, 2, 2, 3) d. syntax error e. [1, 2, 2, 3] Correct Answer c. (1, 2, 2, 3) What is the output of the Python code below? print(dict().get("no", "help!")) a. True b. no c. no help! d. help! e. False Correct Answer d. help! Which of the following types are allowed for Python dictionary keys? a. dictionary b. list c. list of dictionaries d. tuple e. All of the above Correct Answer d. tuple What is the value of the following Python expression? (0, 1, 5, 2) > (0, 1.0, 4, 3.1)
A reserved word that is used by the interpreter to parse programs. Correct Answer Keyword A special symbol that represents a simple computation like addition, multiplication, or string concatenation. Correct Answer Operator A unit of code that the Python interpreter can execute. Correct Answer Statement A name that refers to a value. Correct Answer Variable What output will the following Python 3 statement produce?
print (1,000,000) a. 1. b. 1,000, c. 1 0 0 d. Error invalid type Correct Answer c. 1 0 0 Consider the following Python program. fin = open('words.txt') for line in fin: word = line.strip() print(word) What does the program loop over?
a. Lines in a file b. Lines in a list c. Words in a dictionary d. Words in a list e. Words in a string Correct Answer a. Lines in a file Assume the following Python code has already executed. import os cwd = os.getcwd() Which answer is most likely output from the following Python statement? os.path.isfile(cwd) a. ['Music', 'Pictures', 'Desktop', 'Library', 'Documents', 'Downloads'] b. False c. True d. /Users/me e. /Users/me/Documents/file.txt Correct Answer b. False Assume the following Python code has already executed. import os cwd = os.getcwd()
fin = open('answer.txt') fin.write('Yes') except: print('No') print('Maybe') Select one: a. Yes b. No c. Maybe d. YesMaybe e. NoMaybe Correct Answer e. NoMaybe What is the output of the Python code below? print('%d + %d + %d = %d' % (1, 2, 3, 1+2+3)) a. 6 b. (1 + 2 + 3 = 6) c. None d. 1 + 2 + 3 = 6 e. "1 + 2 + 3 = 6" Correct Answer d. 1 + 2 + 3 = 6 Which of the following Python statements runs without error? a. open('three.txt').write(3) b. open('three.txt','w').write(3) c. open('three.txt','w').write(str(3)) d. All of the above
e. None of the above Correct Answer c. open('three.txt','w').write(str(3)) Assume the following Python code has already executed. import os cwd = os.getcwd() Which answer is most likely output from the following Python statement? os.path.join(cwd, 'Documents/file.txt') a. ['Music', 'Pictures', 'Desktop', 'Library', 'Documents', 'Downloads'] b. False c. True d. /Users/me e. /Users/me/Documents/file.txt Correct Answer e. /Users/me/Documents/file.txt What is the output from the following interactive Python statement?
'%d' % (0.1) a. '0' b. '0.1' c. TypeError: float argument required, not str d. TypeError: not all arguments converted during string formatting
d. a statement e. a value Correct Answer e. a value In Python, the '+' operator can be used with numbers and with strings. What is a property that number addition has, but string concatenation does not? a. Numeric addition is allowed on right-hand side of assignment statement. b. More than one numeric addition per expression is allowed. c. The expression value does not depend on the order of numeric addition operands. d. Numeric addition is fast to execute. e. Numeric addition needs two operands. Correct Answer c. The expression value does not depend on the order of numeric addition operands. What output will the following Python statements produce?
n = 17 print (n) a. 0 b. 17. c. n d. 17 Correct Answer d. 17 What output will the following Python statements produce? percentage = ( 60.0 * 100.0) / 55.
print (percentage) a. percentage b. 109 c. 109. d. 109.0 Correct Answer c. 109. A program is a sequence of instructions that specifies how to perform a computation. Correct Answer True What output will the following Python statement produce? print (2*3-1) a. 6 b. 5 c. 4 d. 3 Correct Answer b. 5 Any one of the languages that people have designed for specific purposes, such as representing mathematical ideas or computer programs; all programming languages are this kind of languages. Correct Answer Formal Language Any one of the languages that people speak that evolved naturally. Correct Answer Natural Language An error that does not occur until the program has started to execute but that prevents the program from continuing. Correct Answer Runtime Error