Every problem in the chapter beside the book’s answer, a chapter at a time as you scroll.
Chapter 1: Statements
64 problems · 0 figuresConcepts in Practice 1.1.1 §1.1 source ↗
- a.3
- b.4
- c.5
Answer
Concepts in Practice 1.1.2 §1.1 source ↗
- a.a tool that summarizes an individual's music preferences
- b.a mobile app for managing and sharing playlists of songs
- c.a website that shows the top artists for the past five years
Answer
Concepts in Practice 1.1.3 §1.1 source ↗
- a.wired headphones that plug into a smartphone
- b.remote control that pauses or skips the current song
- c.wi-fi speaker that streams music from Amazon
Answer
Concepts in Practice 1.1.4 §1.1 source ↗
- a.true
- b.false
Answer
Concepts in Practice 1.1.5 §1.1 source ↗
- a.faster
- b.longer
- c.shorter
Answer
Concepts in Practice 1.1.6 §1.1 source ↗
- a.semicolons
- b.parentheses
- c.quote marks
Answer
Concepts in Practice 1.2.1 §1.2 source ↗
Hello world! as one line of output?- a.
print(Hello world!) - b.
print("Hello", "world", "!") - c.
print("Hello world!")
Answer
print("Hello world!")Concepts in Practice 1.2.2 §1.2 source ↗
Hello world! as one line of output?- a.
print("Hello") print(" world!") - b.
print("Hello") print(" world!", end="") - c.
print("Hello", end="") print(" world!")
Answer
print("Hello", end="")
print(" world!")end="" option removes the newline character after hello, producing Hello world! on the same line.Concepts in Practice 1.2.3 §1.2 source ↗
print("555", "0123", sep="-")- a.
555 0123 - b.
5550123- - c.
555-0123
Answer
555-0123Concepts in Practice 1.2.4 §1.2 source ↗
- a.
input() - b.
today_is = input - c.
today_is = input()
Answer
today_is = input()today_is.Concepts in Practice 1.2.5 §1.2 source ↗
print("Please enter your name: ")
name = input() What is displayed by print("You entered:", name)?- a.
You entered: name - b.
You entered: Sophia - c.
You entered:, Sophia
Answer
You entered: Sophiaprint() function outputs "You entered:" followed by a space character, followed by the input data, Sophia, which is referenced by the variable name.Concepts in Practice 1.2.6 §1.2 source ↗
print("Please enter a number: ")
number = input()
print("Value =", number)- a.
Value = six - b.
Value = 6 - c.
Value = number
Answer
Value = sixConcepts in Practice 1.3.1 §1.3 source ↗
city, after the following assignment?city = "Chicago"
- a.
print("In which city do you live?") - b.
city = "London" - c.
print("The city where you live is", city)
Answer
print("The city where you live is", city) "The city where you live is Chicago" .Concepts in Practice 1.3.2 §1.3 source ↗
- a.
print("Total =", total) total = 6 - b.
total = 6 print("Total =", total) - c.
print("Total =", total) total = input()
Answer
total = 6
print("Total =", total) "Total = 6" .Concepts in Practice 1.3.3 §1.3 source ↗
- a.
: - b.
== - c.
=
Answer
== character is the assignment operator.Concepts in Practice 1.3.4 §1.3 source ↗
- a.
temperature = 98.5 - b.
98.5 = temperature - c.
temperature - 23.2
Answer
temperature = 98.5Concepts in Practice 1.3.5 §1.3 source ↗
- a.median
- b.class
- c.import
Answer
median is a descriptive name for a variable that stores a median value.Concepts in Practice 1.3.6 §1.3 source ↗
2nd_input, not a valid variable name?- a.contains an underscore
- b.starts with a digit
- c.is a keyword
Answer
Concepts in Practice 1.3.7 §1.3 source ↗
- a.
z - b.
var_2 - c.
zip_code
Answer
zip_codeConcepts in Practice 1.3.8 §1.3 source ↗
DogBreed, which improvement conforms to Python's style guide?- a.
dog_breed - b.
dogBreed - c.
dog-breed
Answer
dog_breedConcepts in Practice 1.4.1 §1.4 source ↗
- a.
Hello! - b.
29 - c.
"7 days"
Answer
"7 days" '7 days' is also a string.Concepts in Practice 1.4.2 §1.4 source ↗
email?- a.
"fred78@gmail.com" - b.
"email = fred78@gmail.com" - c.
email = "fred78@gmail.com"
Answer
email = "fred78@gmail.com"fred78@gmail.com, is enclosed in matching double quotes, and is assigned to the variable email. A string can contain characters such as "@" or "." in addition to letters and numbers.Concepts in Practice 1.4.3 §1.4 source ↗
- a.
I know you'll answer correctly! - b.
'I know you'll answer correctly!' - c.
"I know you'll answer correctly!"
Answer
"I know you'll answer correctly!"Concepts in Practice 1.4.4 §1.4 source ↗
- a.
You say "Please" to be polite - b.
"You say "Please" to be polite" - c.
'You say "Please" to be polite'
Answer
'You say "Please" to be polite'Concepts in Practice 1.4.5 §1.4 source ↗
len("Hi Ali")?- a.
2 - b.
5 - c.
6
Answer
6len() function returns the number of characters in the string. 6 characters exist in "Hi Ali" which are "H", "i", " ", "A", "l", and "i".Concepts in Practice 1.4.6 §1.4 source ↗
("")?- a.undefined
- b.0
- c.2
Answer
Concepts in Practice 1.4.7 §1.4 source ↗
number = "12"
number_of_digits = len(number)
print("Number", number, "has", number_of_digits, "digits.")- a.
Number 12 has 12 digits. - b.
Number 12 has 2 digits. - c.
Number 12 has number_of_digits digits.
Answer
Number 12 has 2 digits.number_of_digits variable's value is 2 , and as such, the output is "Number 12 has 2 digits." .Concepts in Practice 1.4.8 §1.4 source ↗
"10"?- a.
1 + 0 - b.
"1 + 0" - c.
"1" + "0"
Answer
"1" + "0" 1 and 0 are enclosed in quotes indicating valid strings, and the + is not, indicating a concatenation operation. Thus, the string "10" is produced. Note that concatenation operator does not include any default separator characters like the space character.Concepts in Practice 1.4.9 §1.4 source ↗
"Awake"?- a.
"wake" + "A" - b.
"A + wake" - c.
"A" + "wake"
Answer
"A" + "wake" "A" and "wake" are valid strings, and the + is not enclosed in quotes, indicating a concatenation operation. Thus the string "Awake" is produced. Note that the concatenation operator does not include any default separator characters like the space character.Concepts in Practice 1.4.10 §1.4 source ↗
"red" after the following line of code. color = input("What is your favorite color?") Which produces the output "Your favorite color is red!"?- a.
print("Your favorite color is " + color + !) - b.
print("Your favorite color is " + "color" + "!") - c.
print("Your favorite color is " + color + "!")
Answer
print("Your favorite color is " + color + "!")Concepts in Practice 1.4.11 §1.4 source ↗
"one-sided" to the variable holiday?- a.
holiday = "one" + "sided" - b.
holiday = one-sided - c.
holiday = "one-" + "sided"
Answer
holiday = "one-" + "sided"holiday. Note that "one-sided" would assign the same string to holiday.Concepts in Practice 1.5.1 §1.5 source ↗
Assume that x = 1, y = 2.0, and s = "32".
print(x, type(x))
- a.
1 'int'. - b.
1.0 <class 'float'>. - c.
1 <class 'int'>.
Answer
1 <class 'int'>.x = 1 is an integer, and when printing the type of an integer variable, the output is <class 'int'>.Concepts in Practice 1.5.2 §1.5 source ↗
Assume that x = 1, y = 2.0, and s = "32".
print(y, type(y))
- a.
2.0 <class 'int'> - b.
2.0 <class 'float'> - c.
2 <class 'int'>
Answer
2.0 <class 'float'>y = 2.0 is floating-point number.Concepts in Practice 1.5.3 §1.5 source ↗
Assume that x = 1, y = 2.0, and s = "32".
"12.0"
- a.
string - b.
int - c.
float
Answer
stringConcepts in Practice 1.5.4 §1.5 source ↗
Assume that x = 7, y = 20, and z = 2.
c = 0 c = x - z c = c + 1 print(c)
- a.
1 - b.
5 - c.
6
Answer
6c = x - z = 7 - 2 = 5. Line 3 increments variable c by 1, making the total equal to 6.Concepts in Practice 1.5.5 §1.5 source ↗
Assume that x = 7, y = 20, and z = 2.
a? a = 3.5 - 1.5
- a.
2 - b.
2.0 - c.
2.5
Answer
2.03.5-1.5 equals 2.0 , which is a floating-point number.Concepts in Practice 1.5.6 §1.5 source ↗
Assume that x = 7, y = 20, and z = 2.
print(x / z)?- a.
3 - b.
3.0 - c.
3.5
Answer
3.57/2 = 3.5.Concepts in Practice 1.5.7 §1.5 source ↗
Assume that x = 7, y = 20, and z = 2.
print(y / z)?- a.
0 - b.
10 - c.
10.0
Answer
10.020/2 equals 10.0 because the division operation results in a float.Concepts in Practice 1.5.8 §1.5 source ↗
Assume that x = 7, y = 20, and z = 2.
print(z * 1.5)?- a.
2 - b.
3 - c.
3.0
Answer
3.02 * 1.5 = 3.0.Concepts in Practice 1.5.9 §1.5 source ↗
4 * 3 ** 2 + 1?- a.
37 - b.
40 - c.
145
Answer
37Concepts in Practice 1.5.10 §1.5 source ↗
(1 + 3) ** 2 / 4 evaluates first?- a.
4 ** 2 - b.
1 + 3 - c.
2 / 4
Answer
1 + 31 + 3 to be evaluated first.Concepts in Practice 1.5.11 §1.5 source ↗
-4 ** 2?- a.
-16 - b.
16
Answer
-16-16 result can be confusing because, in math, "-4 squared" is 16 .Concepts in Practice 1.5.12 §1.5 source ↗
result = -2 ** 3
- a.1
- b.2
- c.3
Answer
=), the negative operator (-), and the exponentiation operator (**).Concepts in Practice 1.6.1 §1.6 source ↗
Given the following error message:
Traceback (most recent call last):
File "/home/student/Desktop/example.py", line 2
print "test"
^
SyntaxError: Missing parentheses in call to 'print'. Did you mean print("test")? What is the filename of the program?- a.Desktop
- b.example.py
- c.test
Answer
Concepts in Practice 1.6.2 §1.6 source ↗
Given the following error message:
Traceback (most recent call last):
File "/home/student/Desktop/example.py", line 2
print "test"
^
SyntaxError: Missing parentheses in call to 'print'. Did you mean print("test")? On which line was the error found?- a.1
- b.2
- c.3
Answer
Concepts in Practice 1.6.3 §1.6 source ↗
Given the following error message:
Traceback (most recent call last):
File "/home/student/Desktop/example.py", line 2
print "test"
^
SyntaxError: Missing parentheses in call to 'print'. Did you mean print("test")? What type of error was found?- a.missing parentheses
- b.
SyntaxError - c.traceback
Answer
SyntaxErrorConcepts in Practice 1.6.4 §1.6 source ↗
For each program below, what type of error will occur?
print("Breakfast options:")
print("A. Cereal")
print("B. Eggs")
print("C. Yogurt")
choice = input("What would you like? ")- a.
IndentationError - b.
NameError - c.
SyntaxError
Answer
IndentationErrorConcepts in Practice 1.6.5 §1.6 source ↗
For each program below, what type of error will occur?
birth = input("Enter your birth date: )
print("Happy birthday on ", birth)- a.
IndentationError - b.
NameError - c.
SyntaxError
Answer
SyntaxErrorConcepts in Practice 1.6.6 §1.6 source ↗
For each program below, what type of error will occur?
print("Breakfast options:")
print(" A. Cereal")
print(" B. Eggs")
print(" C. Yogurt")
choice = intput("What would you like? ")- a.
IndentationError - b.
NameError - c.
SyntaxError
Answer
NameError "input" is misspelled.Concepts in Practice 1.7.1 §1.7 source ↗
- a.avoid writing syntax errors
- b.explain what the code does
- c.make the code run faster
Answer
Concepts in Practice 1.7.2 §1.7 source ↗
- a.#
- b./*
- c.//
Answer
Concepts in Practice 1.7.3 §1.7 source ↗
- a.0 spaces:
#Get the user input - b.1 space:
# Get the user input - c.2 spaces:
# Get the user input
Answer
# Get the user inputConcepts in Practice 1.7.4 §1.7 source ↗
print("You said:", adj1 + " " + noun1)- a.
# Append adj1 and noun1 - b.
# Print out a bunch of stuff - c.
# Show the resulting phrase
Answer
# Show the resulting phraseConcepts in Practice 1.7.5 §1.7 source ↗
1 name = input("Whose birthday is today? ")
2 print("Happy birthday to", name)
3 print("Everyone cheer for", name)- a.After line 1
- b.After line 2
- c.After line 3
Answer
Then again, inserting a blank line in a three-line program is generally unnecessary.
Concepts in Practice 1.7.6 §1.7 source ↗
- a.introduce a syntax error in the line.
- b.remove the line from the program.
- c.insert a # at the beginning of the line.
Answer
Concepts in Practice 1.7.7 §1.7 source ↗
- a.summarize the program's purpose or usage.
- b.explain how each part of the code works.
- c.maintain a list of ideas for new features.
Answer
Concepts in Practice 1.7.8 §1.7 source ↗
- a.
"""Vacations Madlib."""
- b.
"""Vacations Madlib. This program asks the user for two adjectives and two nouns, which are then used to print a funny story about a vacation. """
- c.
# Vacations Madlib. # # This program asks the user for two adjectives # and two nouns, which are then used to print # a funny story about a vacation.
Answer
# Vacations Madlib. # # This program asks the user for two adjectives # and two nouns, which are then used to print # a funny story about a vacation.
Concepts in Practice 1.7.9 §1.7 source ↗
- a.
"""Vacations Madlib."""
- b.
"""Vacations Madlib. This program asks the user for two adjectives and two nouns, which are then used to print a funny story about a vacation. """
- c.
"""Vacations Madlib. This program asks the user for two adjectives and two nouns, which are then used to print a funny story about a vacation. The code uses four variables to store the user input: two for the adjectives, and two for the nouns. The output is displayed on seven lines, beginning with a blank line after the input. """
Answer
"""Vacations Madlib. This program asks the user for two adjectives and two nouns, which are then used to print a funny story about a vacation. """
Concepts in Practice 1.8.1 §1.8 source ↗
- a.British comedy group
- b.Dutch programmer
- c.non-venomous snake
Answer
Concepts in Practice 1.8.2 §1.8 source ↗
- a.Java
- b.Python
Answer
Concepts in Practice 1.8.3 §1.8 source ↗
- a.CWI hired Guido van Rossum to design a new programming language to compete with C++.
- b.Python started out as a hobby and became open source after several years of development.
- c.van Rossum posted Python's source code online after working on the language for one year.
Answer
Concepts in Practice 1.8.4 §1.8 source ↗
- a.C and C++
- b.Java and C
- c.Python and JavaScript
Answer
Concepts in Practice 1.8.5 §1.8 source ↗
- a.2018
- b.2019
- c.2020
Answer
Concepts in Practice 1.8.6 §1.8 source ↗
- a.since 1991
- b.since 2001
- c.since 2015
Answer
Loading chapter 2…
Problems and answers are adapted from Introduction to Python Programming by Udayan Das, Aubrey Lawson, Chris Mayfield and Narges Norouzi, OpenStax, and are used under the CC BY-NC-SA 4.0 licence. Access for free at https://openstax.org/books/introduction-python-programming/pages/1-introduction. Illustrations: Copyright Rice University, OpenStax, under CC BY-NC-SA 4.0 license. This adaptation is released under the same licence, is non-commercial, and is neither affiliated with nor endorsed by OpenStax or Rice University.