Multiple Choice Identify the
choice that best completes the statement or answers the question.
|
|
1.
|
Which Python statement will check to see if a is greater than or equal to
b?
a. | if a >=b: | c. | if a is greater than b | b. | if
a>b: | d. | if (a >
b) |
|
|
2.
|
Which of the following commands can be used to read the entire contents of a
file as a string using the file object <tmpfile>?
a. | tmpfile.read(n) | c. | tmpfile.readline(n) | b. | tmpfile.readlines(n) | d. | tmpfile.read( ) |
|
|
3.
|
What is the output of the following code?
while 4 = =
4: print(‘4’)
a. | 4 is printed infinitely until program closes | c. | Syntax error | b. | 4 is printed
once | d. | 4 is printed four
times |
|
|
4.
|
What is used to take input from the user in Python?
a. | scan( ) | c. | <> | b. | input( ) | d. | print( ) |
|
|
5.
|
Erases the contents of an existing file?
a. | outfile = open(“temp.txt”, “w”) | c. | outfile =
open(“temp.txt”, “r”) | b. | outfile =
open(“temp.txt”,”a”) |
|
|
6.
|
Which data type represents a whole number?
a. | Boolean | c. | String | b. | Float | d. | Integer |
|
|
7.
|
What is used to concatenate two strings in Python?
a. | , operator | c. | # operator | b. | ^ operator | d. | + operator |
|
|
8.
|
In the following code, num is a ____?
num = ‘5’
a. | boolean | c. | float | b. | string | d. | integer |
|
|
9.
|
Which of the following statements is true?
a. | the continue statement is used to skip the rest of the code inside the
loop | c. | All of the above. | b. | the break statement terminates the loop
containing it | d. | the break and
continue statements are almost always used with the if, if...else, and if...elif...else
statements. |
|
|
10.
|
Which of the following is correct?
a. | Reserved words can be used as a variable name | c. | A variable name can have symbols
like: @, #, $ etc. | b. | A variable name can start with a
digit | d. | A variable name can
start with a underscore |
|
|
11.
|
Python statement needed to use math.pi?
a. | import sys | c. | import math | b. | import os | d. | import random |
|
|
12.
|
Which of these would be used to loop through instructions exactly 10
times?
a. | WHILE loop | c. | FOR loop | b. | If statement |
|
|
13.
|
The method to remove an entry from a dictionary is named?
|
|
14.
|
A syntax error in code means:
a. | Python cannot find the file to pass the code to | c. | there was no defined
index | b. | you have not used enough characters | d. | there was an error with your typing and code
structure |
|
|
15.
|
Which term is used to describe expressions that result in the value of either
true or false?
a. | Selection | c. | Boolean | b. | Conditional | d. | Concatenation |
|
|
16.
|
Suppose a list with name test, contains 10 elements. You can get the 5th
element from the test list using:
a. | test[5] | c. | test[‘4’] | b. | test[‘5’] | d. | test[4] |
|
|
17.
|
Comments are ignored by the Python interpreter. What symbol is needed at the
beginning of the comment?
|
|
18.
|
What is used to define a body of a loop?
a. | quotation | c. | parenthesis | b. | indentation | d. | curly braces |
|
|
19.
|
The if..elif..else executes only one block of code among several
blocks.
a. | False | c. | True | b. | It depends on expression
used. | d. | There is no elif
statement in Python |
|
|
20.
|
To obtain the length of a string, you can use which function?
a. | length( ) | c. | index( ) | b. | len( ) | d. | length_input( ) |
|