Skip to main content
Contents Index
Search Book
Search Results:
No results.
Read aloud
Readability settings Prev Up Next Scratch ActiveCode Profile
title here
\(
\newcommand{\lt}{<}
\newcommand{\gt}{>}
\newcommand{\amp}{&}
\definecolor{fillinmathshade}{gray}{0.9}
\newcommand{\fillinmath}[1]{\mathchoice{\colorbox{fillinmathshade}{$\displaystyle \phantom{\,#1\,}$}}{\colorbox{fillinmathshade}{$\textstyle \phantom{\,#1\,}$}}{\colorbox{fillinmathshade}{$\scriptstyle \phantom{\,#1\,}$}}{\colorbox{fillinmathshade}{$\scriptscriptstyle\phantom{\,#1\,}$}}}
\)
Section 1.9 Unit 1 Multiple-Choice Exercises
These are exercises written by Dr. Barb Ericson in the Python for Everybody Interactive ebook on Runestone.
Activity 1.9.1 .
What order do these statements need to appear in to run without any errors?
Statement 1 : alex = turtle.Turtle()
Statement 2 : import turtle
Statement 3 : alex.forward(50)
1-2-3
You must first import the turtle module.
2-3-1
You must create a turtle object before you ask it to do things.
3-1-2
You must first import the turtle module.
2-1-3
Correct! The turtle module needs to be imported and then the turtle needs to be created before it can move forward.
Activity 1.9.2 .
What letter will this Turtle code draw? Remember that the turtle starts facing right at the coordinates (0,0).
import turtle
alex = turtle.Turtle()
alex.forward(75)
alex.goto(0, 0)
alex.right(90)
alex.forward(100)
alex.left(90)
alex.forward(75)
L
Incorrect! Follow every step and try to recreate the shape. Try again.
A
Incorrect! Follow every step and try to recreate the shape. Try again.
C
Correct! The code would create an C shape.
H
Incorrect! Follow every step and try to recreate the shape. Try again.
Activity 1.9.3 .
Which way does the turtle face after this code run? Remember that the turtle initially faces right (east) when placed on the screen.
import turtle
alex = turtle.Turtle()
alex.right(90)
alex.forward(100)
alex.left(90)
alex.forward(150)
alex.left(90)
alex.forward(100)
East
Incorrect! Remember where the turtle initially faces when it is created. Try again.
South
Incorrect! Remember where the turtle initially faces when it is created. Try again
West
Incorrect! Remember where the turtle initially faces when it is created. Try again.
North
Correct! The turtle always start from facing east by default.
Activity 1.9.4 .
What would the following code print?
Mali = 5
print("Mali","is",Mali)
Mali is Mali
Incorrect! There are no quotes around the last Mali, so str() will use the value of the variable Mali. Try again.
Mali is 5
Correct! The first Mali is in quotes, so it will print the string "Mali". The second Mali is not in quotes, so it will print the value of the variable Mali.
5 is Mali
Incorrect! The first Mali is in quotes and the second is not. Try again.
5 is 5
Incorrect! The first Mali is in quotes, so it is a string, not a variable. Try again.
Activity 1.9.5 .
1What is printed by the following statements?
s = "python rocks"
print(s[3])
t
Incorrect! Indices start at 0, not 1. Try again.
h
Correct! Indices start with 0.
c
Incorrect! s[-3] would count from right to left and return c. Try again.
Error, you cannot use the [ ] operator with a string.
Incorrect! [ ] is the index operator and works with strings. Try again.
Activity 1.9.6 .
What is printed by the following statements?
s = "python rocks"
print(s[7:11], s[7:11], s[7:11])
rock rock rock
Correct! s[7:11] = "rock" (from the 7th character up to the 11th but not including 11th), which is then repeated 3 times.
rocks rocks rocks
No because the slice is up to but not the end index. So s[7:11] is "rock", not "rocks". Try again.
python python python
Incorrect! That starts at index 0, not 7. Try again.
rock
Incorrect! It is repeated 3 times. Try again.
Activity 1.9.7 .
What is the value of
15 / 12?
1
Try again, this is the answer for 15 // 12.
1.25
15 / 12 will result in 1.25. The / operator returns a floating point result.
1.5
Try running this in your python interpreter.
3
Try again, this is the answer for 15 % 12.
Activity 1.9.8 .
What is the value of
15 // 12?
1
The // operator returns an integer result (the floor).
1.25
Try again, this is the answer for 15 / 12.
1.5
Try running this in your python interpreter.
3
Try again, this is the answer for 15 % 12.
Activity 1.9.9 .
What is the value of
15 % 12?
1
Try again, this is the answer for 15 // 12.
1.25
Try again, this is the answer for 15 / 12.
1.5
Try running this in your python interpreter.
3
The % (modulo) operator returns the remainder and 12 goes into 15 one time with a remainder of 3.
Activity 1.9.10 .
What is the data type of
'this is what kind of data'?
Character
It is not a single character.
Integer
The data is not numeric.
Float
The value is not numeric with a decimal point.
String
Strings can be enclosed in single quotes.
Activity 1.9.11 .
n = input("Please enter your age: ")
# user types in 18
print ( type(n) )
Activity 1.9.12 .
What is the value of the following expression:
14
Using parentheses, the expression is evaluated as (2*5) first, then (10 // 3), then (16-3), and then (13+1).
24
Remember that * has precedence over -.
3
Remember that // has precedence over -.
13.667
Remember that // does integer division.
Activity 1.9.13 .
After the following statements, what are the values of x and y?
x is 15 and y is 15
Look at the last assignment statement which gives x a different value.
x is 22 and y is 22
No, x and y are two separate variables. Just because x changes in the last assignment statement, it does not change the value that was copied into y in the second statement.
x is 15 and y is 22
Look at the last assignment statement, which reassigns x, and not y.
x is 22 and y is 15
Yes, x has the value 22 and y the value 15.
Activity 1.9.14 .
Given the following code segment, what will be printed?
street = "125 Main Street"
print("The address is " + "street")
The address is street
Since street is in double quotes it will print the string street rather than the value of the variable street.
The address is 125 Main Street
This would be true if it was print("The address is " + street)
It wonβt execute
While this isnβt printing what we probably want it to, it will print something.
Activity 1.9.15 .
Activity 1.9.16 .
Given the following code segment, what will be printed?
friends = 4
name = "Derrik"
print("name" + " has " + str(friends) + " friends")
Derrick has 4 friends
Since name is in quotes it will print those characters rather than the value of name.
name has 4 friends
Since name is in quotes it will print those characters rather than the value of name, but it will print the value of friends after it converts it to a string.
name has friends friends
This would be true if both name and friends were in quotes.
There will be an error
This would be true if the friends can not been converted to a string
Activity 1.9.17 .
Given the following code segment, what will be printed?
pets = 2
name = "Mariah"
print(name + " has " + pets + " pets")
Mariah has 2 pets
This would be true if there wasnβt an error
name has 2 pets
This would be true if name was in quotes
Mariah has pets pets
This would be true if pets was in quotes
There will be an error
You canβt concatenate an integer with a string. You need to convert it to a string first.
You have attempted
of
activities on this page.