Python Vocab 1
How many values can be used at a time with each of the following operators? not
1
Label each of the following as either a "Read", a "Write", or a "Read and Write" for the variable price. price = 0
Write
Given the following code: movies = [ {"Name": "Iron Man", "Length": 126, "Characters": ["Tony", "Pepper", "Obidiah"]}, {"Name": "Thor", "Length": 130, "Characters": ["Thor", "Jane", "Loki"]}, {"Name": "Captain America", "Length": 126, "Characters": ["Steve", "Peggy", "Bucky"]}] What is the value of the following expressions? movies[-1]["Length"]
126
x = 22 def reset_x(): x = x+1 reset_x() print (x) What does this code print? A)Error, the function does not have any parameter. B) Error, 'x' referenced before assignment C)22 D)0
B) Error, 'x' referenced before assignment
T or F You should not put error messages into help seeking emails because it can clutter up the email.
F
TorF Dictionaries are useful because you can have duplicate keys.
F
T or F A for loop will process a file sentence-by-sentence.
F The Iteration Variable will take on each value of the List Variable, one at a time.
Evaluate whether each of the following expressions are True, False, or cause an error. Apply the rules of Truthiness when they are not boolean expressions. Assume the following code is run first: quote = "I like turtles" "1" + "1" == "2"
False
Evaluate whether each of the following expressions are True, False, or cause an error. Apply the rules of Truthiness when they are not boolean expressions. Assume the following code is run first: quote = "I like turtles" "quote" in quote
False
Evaluate whether each of the following expressions are True, False, or cause an error. Apply the rules of Truthiness when they are not boolean expressions. Assume the following code is run first: quote = "I like turtles" 10 == "10"
False
Evaluate whether each of the following expressions are True, False, or cause an error. Apply the rules of Truthiness when they are not boolean expressions. Assume the following code is run first: quote = "I like turtles" False
False
Evaluate whether each of the following expressions are True, False, or cause an error. Apply the rules of Truthiness when they are not boolean expressions. Assume the following code is run first: quote = "I like turtles" not True and False
False
Evaluate whether each of the following expressions are True, False, or cause an error. Apply the rules of Truthiness when they are not boolean expressions. Assume the following code is run first: quote = "I like turtles" []
False
Select each of the following if the expression evaluates to True, according to the rules of Truthiness in Python. "".upper()
False Empty string evaluates as False
Select each of the following if the expression evaluates to True, according to the rules of Truthiness in Python. 8-4*2
False order of operations so 8-4*2 = 0 because non-zero numbers integers evaluate as True A zero integer evaluates as False.
Which of the following types are sequences? File Tuple Float Dictionary Boolean Integer String List
File Tuple Dictionary String List
Evaluate the type of each of the following value: -1.4
Float
Evaluate the type of the following expressions. Assume the following code is run first: name = "Python" grade = 100.0 4/5
Float
Evaluate the type of the following expressions. Assume the following code is run first: name = "Python" grade = 100.0 grade - grade
Float
Select each of the following if the expression evaluates to True, according to the rules of Truthiness in Python. "False"
True, because non empty string
Evaluate the type of each of the following value: (1, 2, 3)
Tuple
Classify each of the following as Python keywords, types, values, or built-in functions. Boolean
Type
Classify each of the following as Python keywords, types, values, or built-in functions. Dictionary
Type
Classify each of the following as Python keywords, types, values, or built-in functions. Float
Type
Classify each of the following as Python keywords, types, values, or built-in functions. Integer
Type
Classify each of the following as Python keywords, types, values, or built-in functions. {1:2}
Value
Classify each of the following as Python keywords, types, values, or built-in functions. ""
Value
Classify each of the following as Python keywords, types, values, or built-in functions. []
Value
if statement
A control structure for branching the execution of a program
For Loop
A control structure for performing actions on each element of a sequence
dictionary
A data structure for mapping keys to values
List
A data structure for storing elements in an ordered sequence
Variable
A name that can be associated with a value
function
A reusable chunk of code with inputs and outputs
Program
A sequence of coded instructions that manipulate data inside a computer
File
A sequence of data stored in your computer's long term memory
Given the following code: movies = [ {"Name": "Iron Man", "Length": 126, "Characters": ["Tony", "Pepper", "Obidiah"]}, {"Name": "Thor", "Length": 130, "Characters": ["Thor", "Jane", "Loki"]}, {"Name": "Captain America", "Length": 126, "Characters": ["Steve", "Peggy", "Bucky"]}] What is the value of the following expressions? movies[2]["Name"]
"Captain America"
The function sayHi below returns the string "Hi". What value will the variable x hold after the line is executed? x = sayHi() + sayHi() + sayHi()
"HiHiHi"
Given the following code: movies = [ {"Name": "Iron Man", "Length": 126, "Characters": ["Tony", "Pepper", "Obidiah"]}, {"Name": "Thor", "Length": 130, "Characters": ["Thor", "Jane", "Loki"]}, {"Name": "Captain America", "Length": 126, "Characters": ["Steve", "Peggy", "Bucky"]}] What is the value of the following expressions? movies[0]["Name"]
"Iron Man"
Given the following code: movies = [ {"Name": "Iron Man", "Length": 126, "Characters": ["Tony", "Pepper", "Obidiah"]}, {"Name": "Thor", "Length": 130, "Characters": ["Thor", "Jane", "Loki"]}, {"Name": "Captain America", "Length": 126, "Characters": ["Steve", "Peggy", "Bucky"]}] What is the value of the following expressions? movies[1]["Characters"][2]
"Loki"
Given the following code: movies = [ {"Name": "Iron Man", "Length": 126, "Characters": ["Tony", "Pepper", "Obidiah"]}, {"Name": "Thor", "Length": 130, "Characters": ["Thor", "Jane", "Loki"]}, {"Name": "Captain America", "Length": 126, "Characters": ["Steve", "Peggy", "Bucky"]}] What is the value of the following expressions? movies[2]["Characters"][0]
"Steve"
What is printed after the code below is executed? def calculate_sum(values): sum = 0 for value in values: sum = sum + value return sum sum = 0 calculate_sum([1, 2, 3]) print(sum)
0 because at first the function sums all items in list and return 6 but at the end the sum is restated as the sum=0
def f(x): return x*x for n in [1, 2, 3]: total = 1 + f(n) print(total) What does this code print?
10 looks at each item in the list [1,2,3] first looks at item in list then returns the square of the item plus one. Once reaches the end of the list (i.e. 3) and squares and add one the value is then printed and the result is 10. 1^2+1 3 2^2+1 5 3^2+1 10 <---prints last total So the answer is: 10
How many values can be used at a time with each of the following operators? +
2
How many values can be used at a time with each of the following operators? and
2
How many values can be used at a time with each of the following operators? !=
2
How many branches do each of these code snippets have? if conditional: print(4) print(4) if conditional: print(1) else: print(3) if conditional1: if conditional2: print(4) print(3) print(2)
2 2 3
x = 22 def reset_x(): x = 0 reset_x() print(x) What does this code print?
22
After the second iteration of the loop, what is the value of sum? sum = 0 values = [4, 2, 6] for value in values: sum = sum + value
2nd interation sum is 6 because the program evaluates as: 4=0+4 (1st time sum= 4) 6=4+2 (2nd time sum=6) 12=6+6 (3rd time sum=12)
What will be printed after this code is run? points = {"Virginia Tech": 5} points["Virginia Tech"] = 3 print(points["Virginia Tech"])
3
command = "" words = [] while command != "quit": command = input("Give me another word:") words.append("Said "+command) print(words) How many times does the loop body below execute? At least twice None No more than four times At least once
At least once
Type
A categorization of values of similar kinds that determines what you can do with the values.
Module
A collection of functions, classes, and variables available to be imported
String
A type that represents textual data
What does the pass do? Passes the result of the function back to where it was Passes a value to a function Absolutely nothing
Absolutely Nothing
What is the value of the variable x after this code is run? values = [-1, -2, 2, 3] x = False for value in values: x = x or value > 0 print(x)
Answer: True The program looks at each value in the list and sets x=False and runs like this: False or -1>0 so, False or False result: False False or -2>0 so, False or False result:False False or 2>0 so False or True result: True False or 3>0 so False or true result: True So, print the last result so print(True) evaluates as True.
Evaluate the type of each of the following value: True
Boolean
Evaluate the type of the following expressions. Assume the following code is run first: name = "Python" grade = 100.0 1 < 5.0
Boolean
Evaluate the type of the following expressions. Assume the following code is run first: name = "Python" grade = 100.0 1+1 < 5 or 4 > 3
Boolean
Evaluate the type of the following expressions. Assume the following code is run first: name = "Python" grade = 100.0 True or False
Boolean
Evaluate the type of each of the following value: {1:2}
Dictionary
Evaluate the type of each of the following value: {}
Dictionary
Evaluate the type of the following expressions. Assume the following code is run first: name = "Python" grade = 100.0 {name: grade}
Dictionary
What is the type of the iteration variable in this code? groceries = [{"Name": "Apple", "Cost": 1.99, "Calories":20}, {"Name": "Cookie", "Cost": 4.99, "Calories": 300}, {"Name": "Steak", "Cost": 6.99, "Calories": 100}] for grocery in groceries: print(grocery) Float Integer Dictionary List String
Dictionary
T or F Variables in Python are used to solve for unknown values, like in Algebra.
F
Evaluate whether each of the following expressions are True, False, or cause an error. Apply the rules of Truthiness when they are not boolean expressions. Assume the following code is run first: quote = "I like turtles" [1, 2, 3] < 5
Error TypeError: '<' not supported between instances of 'list' and 'int'
T or F Humans discovered programming languages in the 1940s and have been decoding them ever since.
F
T or F A for loop will process a file sentence-by-sentence.
F
T or F A while loop will always execute at least once.
F
T or F Dictionaries cannot be composed of Lists.
F
T or F Dictionaries will always have at least one key and one value.
F
T or F Every function created with the def keyword must have AT LEAST ONE parameter.
F
T or F Expressions are always evaluated from left to right.
F
T or F Once a function returns a variable, that variable is available outside of the function.
F
T or F Printing is the same thing as returning.
F
T or F Strings are composed of only letters and symbols.
F
T or F The body of a for loop will contain one statement for each element of the iteration list.
F
T or F The open function consumes a String representing a path and returns a String of the file's contents.
F
T or F The print function can only print literal values.
F
T or F The print function is necessary to call a function.
F
T or F The statement count = count + 1 will cause an error because no number can be greater than itself.
F
T or F Tuples are composed of key/value pairs.
F
T or F Variable names are important because computers understand the meaning of names and change their value accordingly
F
T or F Variable names are important because computers understand the meaning of names and change their value accordingly.
F
Select each of the following if the expression evaluates to True, according to the rules of Truthiness in Python. -0
False
Select each of the following if the expression evaluates to True, according to the rules of Truthiness in Python. 5 < 4 and 3
False
T or F You can nest if statements inside of other if statements, but not inside functions.
False
Evaluate the type of each of the following value : 5
Integer
Evaluate the type of each of the following value: -1000057
Integer
Evaluate the type of the following expressions. Assume the following code is run first: name = "Python" grade = 100.0 1+1
Integer
Evaluate the type of the following expressions. Assume the following code is run first: name = "Python" grade = 100.0 100-99
Integer
Evaluate the type of the following expressions. Assume the following code is run first: name = "Python" grade = 100.0 [0][0]
Integer
Given this dictionary... animal = {"Name": "Pumpkin", "Age": 2, "Small?": True} What is the type of the value associated with the key "Age"?
Integer
Which of the following are possible subtypes for a list? Integer List Dictionary Boolean String
Integer List Dictionary Boolean String
Evaluate the type of each of the following value: [1, 2, 3]
List
Evaluate the type of each of the following value: []
List
Evaluate the type of the following expressions. Assume the following code is run first: name = "Python" grade = 100.0 [name]
List
Evaluate the type of the following expressions. Assume the following code is run first: name = "Python" grade = 100.0 "1,2,3,4".split(",")
List result: ['1', '2', '3', '4']
Label each of the following as a function call, method call, or not a call. function.call()
Method Call
Evaluate the type of each of the following value: None
None
When the following code is executed, what will be the value of the variable named greeting? def make_greeting(name): print("Hello", name) greeting = make_greeting("Mr. Anderson") "HelloMr. Anderson" "Mr. Anderson" "Hello Mr. Anderson" None
None None, because there is no explicit return statement so None is the default value for all variables
Which of the following can be involved in an expression? Other expressions Statements Values Variables Conditional operators Mathematical operators
Other expressions Statements (Cannot be in expressions) evaluates=expression vs. statements=do not evaluate/assigns Values Variables Conditional operators Mathematical operators
Given the following code: movies = [ {"Name": "Iron Man", "Length": 126, "Characters": ["Tony", "Pepper", "Obidiah"]}, {"Name": "Thor", "Length": 130, "Characters": ["Thor", "Jane", "Loki"]}, {"Name": "Captain America", "Length": 126, "Characters": ["Steve", "Peggy", "Bucky"]}] What is the value of the following expressions? movies[0][127]
Raises a error
Given the following code: movies = [ {"Name": "Iron Man", "Length": 126, "Characters": ["Tony", "Pepper", "Obidiah"]}, {"Name": "Thor", "Length": 130, "Characters": ["Thor", "Jane", "Loki"]}, {"Name": "Captain America", "Length": 126, "Characters": ["Steve", "Peggy", "Bucky"]}] What is the value of the following expressions? movies[2]["Steve"]
Raises an error
Given the following code: movies = [ {"Name": "Iron Man", "Length": 126, "Characters": ["Tony", "Pepper", "Obidiah"]}, {"Name": "Thor", "Length": 130, "Characters": ["Thor", "Jane", "Loki"]}, {"Name": "Captain America", "Length": 126, "Characters": ["Steve", "Peggy", "Bucky"]}] What is the value of the following expressions? movies[1][1]
Raises an error
Label each of the following as either a "Read", a "Write", or a "Read and Write" for the variable price. adjusted = price * tax
Read
Label each of the following as either a "Read", a "Write", or a "Read and Write" for the variable price. print(price)
Read
Label each of the following as either a "Read", a "Write", or a "Read and Write" for the variable price. price = price * .9
Read & write To write to a variable, you put its name on the left side of an "assignment statement". To read from a variable, you simply use its name.
Match the type of graph with the kind of question it is most suited to. Histogram, Line plot, Scatter Plot The relationships of a list of numbers The distribution of a list of numbers The trend in a list of numbers
Scatter Plot Histogram Line plot
Literal Value
Specific instances of data written directly in source code
Evaluate the type of each of the following value: "True"
String
Evaluate the type of each of the following value: ''
String
Evaluate the type of each of the following value: "2.0"
String
Evaluate the type of each of the following value: "Python"
String
Evaluate the type of the following expressions. Assume the following code is run first: name = "Python" grade = 100.0 "1"+"1"
String
Evaluate the type of the following expressions. Assume the following code is run first: name = "Python" grade = 100.0 name[0]
String
Given the file named scores.txt with the following contents: 44, 23, 37 And the following python code: score_file = open("scores.txt") score_data = score_file.read() What will be the type of score_data? List of integer List of string File object Dictionary of integers and strings String Integer
String
Given this dictionary... animal = {"Name": "Pumpkin", "Age": 2, "Small?": True} What is the type of the key "Name"?
String
Given this dictionary... animal = {"Name": "Pumpkin", "Age": 2, "Small?": True} What is the type of the key "Small?"?
String
Given this dictionary... animal = {"Name": "Pumpkin", "Age": 2, "Small?": True} What is the type of the value associated with the key "Name"?
String
Given the file named scores.txt with the following contents: 44, 23, 37 And the following python code: score_file = open("scores.txt") score_data = score_file.read() What will be the type of score_data? List of integer List of string File object Dictionary of integers and strings String Integer
String The primary way to get data from a file is to use the ".read()" method. This simply returns the contents of the file as a single string.
T or F Keys can be added to a dictionary after the dictionary has been created.
T
T or F Like an if statement and a function call, the for Loop might cause the execution to not follow the sequential order of lines.
T
T or F List comprehensions cannot express everything that a for loop can.
T
T or F Lists can be composed of Dictionaries.
T
T or F Normally, statements are executed from top to bottom.
T
T or F The Iteration Variable will take on each value of the List Variable, one at a time.
T
T or F The given program does not correctly close the file: def has_a_cat(filename): a_file = open(filename) return "cat" in a_file.read() a_file.close() has_a_cat("story.txt")
T
T or F Unlike Lists, Tuples are immutable, meaning Tuples cannot be changed after they are created.
T
T or F Variables change their value over time according to the instructions in a program.
T
T or F You must import the json module before you can use the load function.
T
T or F 1. A function without an explicit return statement returns None . 2. We can return multiple times in a function. 3. We can print multiple times in a function. 4. A function ends with return.
T F T T
Evaluate whether each of the following expressions are True, False, or cause an error. Apply the rules of Truthiness when they are not boolean expressions. Assume the following code is run first: quote = "I like turtles" "" in quote
True
Evaluate whether each of the following expressions are True, False, or cause an error. Apply the rules of Truthiness when they are not boolean expressions. Assume the following code is run first: quote = "I like turtles" "False" == "False"
True
Evaluate whether each of the following expressions are True, False, or cause an error. Apply the rules of Truthiness when they are not boolean expressions. Assume the following code is run first: quote = "I like turtles" 10 == 10.0
True
Evaluate whether each of the following expressions are True, False, or cause an error. Apply the rules of Truthiness when they are not boolean expressions. Assume the following code is run first: quote = "I like turtles" 3<5
True
Evaluate whether each of the following expressions are True, False, or cause an error. Apply the rules of Truthiness when they are not boolean expressions. Assume the following code is run first: quote = "I like turtles" 5 < 4 or 3 == 3
True
Evaluate whether each of the following expressions are True, False, or cause an error. Apply the rules of Truthiness when they are not boolean expressions. Assume the following code is run first: quote = "I like turtles" 5 in [1, 3, 5]
True
Evaluate whether each of the following expressions are True, False, or cause an error. Apply the rules of Truthiness when they are not boolean expressions. Assume the following code is run first: quote = "I like turtles" True or (True and False)
True
Evaluate whether each of the following expressions are True, False, or cause an error. Apply the rules of Truthiness when they are not boolean expressions. Assume the following code is run first: quote = "I like turtles" not False
True
Evaluate whether each of the following expressions are True, False, or cause an error. Apply the rules of Truthiness when they are not boolean expressions. Assume the following code is run first: quote = "I like turtles" " " in quote
True
Evaluate whether each of the following expressions are True, False, or cause an error. Apply the rules of Truthiness when they are not boolean expressions. Assume the following code is run first: quote = "I like turtles" "Alaska" < "Delaware"
True
Evaluate whether each of the following expressions are True, False, or cause an error. Apply the rules of Truthiness when they are not boolean expressions. Assume the following code is run first: quote = "I like turtles" "turtle" in quote
True
Select each of the following if the expression evaluates to True, according to the rules of Truthiness in Python. 1 or 0
True
Select each of the following if the expression evaluates to True, according to the rules of Truthiness in Python. 1
True
The input function does which of the following? Writes output to the console Returns a string Consumes arguments Retrieves input from the user
Writes output to the console Returns a string Consumes arguments Retrieves input from the user
The print function does which of the following? Returns a string Writes output to the console Retrieves input from the user Consumes arguments
Writes output to the console & Consumes arguments
my_var = 18 my_list = [my_var, 2, 3] myvar = 22 print(my_list) print(myvar) What does this code print?
[18, 2, 3] 22 watch out for variable names and the underscore.
a_list = [1, 2, 3] myvar = a_list[0] a_list[0] = 18 print (a_list) print (myvar) What does this code print?
[18, 2, 3] 1
Select each of the following if the expression evaluates to True, according to the rules of Truthiness in Python. "Hermione"[4:4]
[4:4] evaluates as an empty string which empty strings evaluate as False.
Choose which of the following are valid Python variable names. Note that they do not have to be good variable names, just valid. first name book-title _27_ BankAccount 5th_value "dogs_list" stor_txt
_27_ BankAccount stor_text
Which of the following demonstrates proper syntax for accessing a dictionary's value? {"Key"}a_dictionary a_dictionary{"Key"} a_dictionary["Key"] ["Key"]a_dictionary
a_dictionary["Key"]
Classify each of the following as Python keywords, types, values, or built-in functions. input
built in function
Classify each of the following as Python keywords, types, values, or built-in functions. print
built-in-function
Given the following code, dict = {"Key": "Value", 7: 8, True: "Hello"} key = 7 Which of the following are valid expressions? dict[True] dict["Key"] dict["He"+"llo"] dict[False] dict[Key] dict[8] dict["Value"] dict[key] dict[7]
dict[True] dict["Key"] dict[key] dict[7]
Label each of the following as a function call, method call, or not a call. method()
function call
Label each of the following as a function call, method call, or not a call. print()
function call
Which of the following have a body? Dictionary access if statement. for loop Function definition List comprehension while loop Function call
if statement. for loop Function definition while loop
Which of the following two snippets of code are equal? from json import load file = open("scores.txt") load(file) import json as js file = open("scores.txt") json.load(file) from json import load file = open("scores.txt") json.load(file) import load file = open("scores.txt") load(file) import json file = open("scores.txt") json.load(file)
import json file = open("scores.txt") json.load(file) from json import load file = open("scores.txt") load(file)
Is the print call before, inside, or after the for loop?
inside
Classify each of the following as Python keywords, types, values, or built-in functions. return
key word
Classify each of the following as Python keywords, types, values, or built-in functions. def
keyword
Classify each of the following as Python keywords, types, values, or built-in functions. for
keyword
Classify each of the following as Python keywords, types, values, or built-in functions. import
keyword
Classify each of the following as Python keywords, types, values, or built-in functions. in
keyword
Classify each of the following as Python keywords, types, values, or built-in functions. while
keyword
Label each of the following as a function call, method call, or not a call. "function".method()
method call
Which of the following expressions creates two new variables? "month", "year" = 11, 17 month = year date = 11, 17 month, year = (11, 17) month = 11
month, year = (11, 17)
Select each of the following if the expression evaluates to True, according to the rules of Truthiness in Python. '"'
non-empty string so its true
Label each of the following as a function call, method call, or not a call. (input)
not a call
Label each of the following as a function call, method call, or not a call. file.(close)
not a call
Assume that the following code is run: values = [1,2,3] word = "Python" Predict the output of each of the following operations: print(word[ -2: ])
print(word[ -2: ] =on letters from -2 spot to end, including -2 spot
Assume that the following code is run: values = [1,2,3] word = "Python" Predict the output of each of the following operations: print(word[ 3:4 ])
print(word[ 3:4 ]) = h letters from 3rd spot to the 4th spot, not including 4 spot
Assume that the following code is run: values = [1,2,3] word = "Python" Predict the output of each of the following operations: print(word[ :2 ])
print(word[ :2 ]) =Py letters before 2 spot, not including 2 spot
Given the program below, name = input("What is your name?") def fix_capitalization(name): return name.title().strip() def print_message(name): print("Hello", name, "how are you?") Which of the following lines of code will have the data flow correctly through both functions in order to print the message with the fixed capitalization? None are necessary, because the variables share the same name. print(fix_capitalization(name)) print(print_message(name)) fix_capitalization(name) print_message(name) print_message(fix_capitalization(name)) name = fix_capitalization(name) print_message(name) fix_capitalization() print_message()
print_message(fix_capitalization(name)) name = fix_capitalization(name) print_message(name)
Given the following code: movies = [ {"Name": "Iron Man", "Length": 126, "Characters": ["Tony", "Pepper", "Obidiah"]}, {"Name": "Thor", "Length": 130, "Characters": ["Thor", "Jane", "Loki"]}, {"Name": "Captain America", "Length": 126, "Characters": ["Steve", "Peggy", "Bucky"]}] What is the value of the following expressions? movies[127]["Name"]
raises an error
Given the following code: movies = [ {"Name": "Iron Man", "Length": 126, "Characters": ["Tony", "Pepper", "Obidiah"]}, {"Name": "Thor", "Length": 130, "Characters": ["Thor", "Jane", "Loki"]}, {"Name": "Captain America", "Length": 126, "Characters": ["Steve", "Peggy", "Bucky"]}] What is the value of the following expressions? movies[2]["Characters"]["Steve"]
raises an error
While Loop
repeatedly executes a target statement as long as a given condition is true.
Classify each of the following as Python keywords, types, values, or built-in functions. List
type
Classify each of the following as Python keywords, types, values, or built-in functions. string
type
Classify each of the following as Python keywords, types, values, or built-in functions. 5
value
Classify each of the following as Python keywords, types, values, or built-in functions. True
value