SOLUTIONS
A ___________________________ is a collection of
programming instructions that can be applied to an object.
Correct Answers method
A numeric constant that appears in your code without
explanation is known as a: Correct Answers magic number
A sequence of characters is referred to as a Correct Answers
string
A variable is: Correct Answers An expression
A(n) _____________________ is a collection of code that has
been written by someone else that is ready for you to use in your
program. (Chapter 2.2) Correct Answers library
A(n) _____________________ is a collection of programming
instructions that carry out a particular task. Correct Answers
function
Assume that s is an arbitrary string containing at least 2
characters. What is displayed by the following code segment?
print(s[0], s[len(s) - 1]) Correct Answers The first character of
s, followed by a space, followed by the last character of s.
Assume that you have an integer variable, pennies, that currently
contains an integer number of pennies. Which statement
determines the number of dollars and cents for that number of
,pennies? Correct Answers dollars = pennies // 100cents =
pennies % 100
Consider the following code segment:
a = input("Enter the value of a: ")
b = input("Enter the value of b: ")
print(a + b) Correct Answers 15
Consider the following code segment:
product = "Cookies"
product = product.lower( Correct Answers "cookies"
Consider the following code segment:
title = "Python for Everyone" newTitle = title.replace("e", "*")
After this code runs, the value stored in newTitle is: Correct
Answers "Python for Ev*ryon*"
Consider the following code segment:
x = 12 print("%d%%" % x)
The output generated by this code segment is: Correct Answers
12%
Consider the following code segment:
x = 5 y = 3 z = 2 result = x // y + x % z Correct Answers 2
Consider the following code segment:
x = 5 y = 7 z = x - y * 2 Correct Answers -9
Given the code snippet below, what code is needed to print the
person's initials?
firstName = "Pamela"
, middleName = "Rose"
lastName = "Smith" Correct Answers print(firstName[0],
middleName[0], lastName[0])
How is a value stored in a variable? Correct Answers an
assignment statement
num = int("45") * float("1.5") print(num) Correct Answers
67.5
The following code snippet has an error, how can this be
corrected so it prints: 123 Main Street?
1. street = " Main Street"
2. address = 123 + street
3. print(address) Correct Answers change the value '123' in
line 2 to a string using the str function
The line of code that displays the floating point number stored in
the variable x using 3 decimal places is: Correct Answers
print("%.3f" % x)
The line of code which reads a value from the user and stores it
in a variable named x as a floating-point value is: Correct
Answers x = float(input("Enter the value of x: "))
The message used to tell the user what input is expected is
known as a(n): Correct Answers prompt
The Python code that represents the formula c = (a / b)3 is:
Correct Answers c = (a / b) ** 3