Answers
print greet.upper() - Answer-(Chapter 6) How would you print out the following variable
in all upper case in Python?
greet = 'Hello Bob'
twist() - Answer-(Chapter 6) Which of the following is not a valid string method in
Python?
.ma - Answer-(Chapter 6)
What will the following Python code print out?
data = 'From Sat Jan 5 09:14:16 2008'
pos = data.find('.')
print data[pos:pos+3]
strip() - Answer-(Chapter 6) Which of the following string methods removes whitespace
from both the beginning and end of a string?
Collection variables can store multiple values in a single variable - Answer-(Chapter 8)
How are "collection" variables different from normal variables?
print len(data) - Answer-(Chapter 8) Which of the following Python statements would
print out the length of a list stored in the variable data?
A list of integers - Answer-(Chapter 8) What type of data is produced when you call the
range() function?
x = range(5)
append() - Answer-(Chapter 8) What list method adds a new item to the end of an
existing list?
for / in - Answer-(Chapter 8) What are the Python keywords used to construct a loop to
iterate through a list?
print friends[2] - Answer-(Chapter 8) For the following list, how would you print out
'Sally'?
friends = [ 'Joseph', 'Glenn', 'Sally' ]
6 - Answer-(Chapter 8) What does the following Python code print out?
,a = [1, 2, 3]
b = [4, 5, 6]
c=a+b
print len(c)
Glenn - Answer-(Chapter 8)
What will the following Python code print out?
friends = [ 'Joseph', 'Glenn', 'Sally' ]
friends.sort()
print friends[0]
t[2:4] - Answer-(Chapter 8) Which of the following slicing operations will produce the list
[12, 3]?
t = [9, 41, 12, 3, 74, 15]
Nothing would print - the program fails with a traceback - Answer-(Chapter 8) What
would the following Python code print out?
fruit = 'Banana'
fruit[0] = 'b'
print fruit
Zap
ABC
Zap - Answer-(Midterm) What will the following Python program print out:
What Python statement would you like me to run? - Answer-(Chapter 1) When Python is
running in the interactive mode and displaying the chevron prompt (>>>) - what question
is Python asking you?
20 - Answer-(Chapter 1) What will the following program print out:
>>> x = 15
>>> x = x + 5
>>> print x
.py - Answer-(Chapter 1) Python scripts (files) have names that end with:
for - Answer-(Chapter 1) Which of these words is a reserved word in Python ?
, quit() - Answer-(Chapter 1) What is the proper way to say "good-bye" to Python?
Central Processing Unit - Answer-(Chapter 1) Which of the parts of a computer actually
execute the program instructions?
A sequence of instructions in a programming language - Answer-(Chapter 1) What is
"code" in the context of this course?
Secondary Memory - Answer-(Chapter 1) A USB memory stick is an example of which
of the following components of computer architecture?
The computer did not understand the statement that you entered - Answer-(Chapter 1)
What is the best way to think about a "Syntax Error" while programming?
Random steps - Answer-(Chapter 1) Which of the following is not one of the
programming patterns covered in Chapter 1?
# This is a test - Answer-(Chapter 2) Which of the following is a comment in Python?
123abc - Answer-(Chapter 2) What does the following code print out?
hours - Answer-(Chapter 2) Which of the following variables is the "most mnemonic"?
stop - Answer-(Chapter 2) Which of the following variables is the "most mnemonic"?
Retrieve the current value for x, add two to it and put the sum back into x - Answer-
(Chapter 2) What does the following statement do? x = x + 2
Parenthesis () - Answer-(Chapter 2) Which of the following elements of a mathematical
expression in Python is evaluated first?
2 - Answer-(Chapter 2) What is the value of the following expression? 42 % 10
5 - Answer-(Chapter 2) What is the value in x after the following statement executes: x =
1+2*3-8/4
98 - Answer-(Chapter 2) What value be in the variable x when the following statement is
executed?
x = int(98.6)
Pause the program and read data from the user - Answer-(Chapter 2) What does the
Python raw_input() function do?
Indent the line below the if statement - Answer-(Chapter 3)
What do we do to a Python statement that is immediately after an if statement to
indicate that the statement is to be executed only when the if statement is true?