Python Final

¡Supera tus tareas y exámenes ahora con Quizwiz!

You can store a List as one of the keys of a Dictionary.

false

Label each of the following as either a "Read", a "Write", or a "Read and Write" for the variable price. price = 0 print(price) adjusted = price * tax price = price * .9

write, read, read, read and write

Which of the following is the best description of this line of code? from math import sqrt as square_root

Loads the sqrt function in the math module but renames it square_root

Which of the following can be involved in an expression? other expressions values mathematical operators variables conditional operators statements

all but statements

What types are possible subtypes for a list?

anything

How many times does the loop body below execute? command = "" words = [] while command != "quit": command = input("Give me another word:") words.append("Said "+command) print(words)

at least once

A data structure for storing elements in an ordered sequence

list

Specific instances of data written directly in source code

literal value

A sequence of coded instructions that manipulate data inside a computer

program

5

value

How do you write each of the following as string literal values? a tab character a new line a double quote a single quote

"\t" "\n" "\"" '\''

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"] movies[2]["Name"] movies[0][127] movies[1][1] movies[127]["Name"] movies[2]["Characters"][0] movies[2]["Characters"]["Steve"] movies[1]["Characters"][2] movies[2]["Steve"] movies[-1]["Length"]

"Iron Man", "Captain America", Raises an error, Raises an error, Raises my error, "Steve", Raises an error, Loki, Raises an error, 126

How many values can be used at a time with each of the following operators? + not and !=

2,1,2,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 conditional1: 2: print(4) print(3) print(2)

2,2,3

What will be printed after this code is run? points = {"Virginia Tech": 5} points["Virginia Tech"] = 3 print(points["Virginia Tech"])

3

Which of the following two snippets of code are equal? 1. from json import load file = open("scores.txt") json.load(file) 2. import load file = open("scores.txt") load(file) 3. from json import load file = open("scores.txt") load(file) 4. import json as js file = open("scores.txt") json.load(file) 5. import json file = open("scores.txt") json.load(file)

3,5

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

6

If an if statement is nested inside another if statement, how many spaces will the body of the inner if statement have?

8

What is the value of tax after this program executes? if False: tax = 5 print(tax)

No value, because an error occurs since the value has not been defined

When the following code is executed, what will be the value of the variable named greeting?

None

Histogram

The distribution of a list of numbers

scatter plot

The relationship between two lists of numbers

Line plot

The trend in a list of numbers

Which of the following demonstrates proper syntax for accessing a dictionary's value?

a_dictionary["Key"]

What does the pass do?

absolutely nothing

The input function does which of the following? consumes arguments returns a string retrieves input from the user writes output to the console

all

input

built-in function

print

built-in function

The print function does which of the following? consumes arguments writes output to the console returns a string retrieves input from the user

consumes arguments, writes output to the console

Given the following code, dict = {"Key": "Value", 7: 8, True: "Hello"} key = 7 Which of the following are valid expressions? dict[7] dict["Value"] dict[key] dict[8] dict[Key] dict["Key"] dict[False] dict[True] dict["He"+"llo"]

dict[7], dict[key], dict["Key"], dict[True]

A data structure for mapping keys to values

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)

dictionary

A for loop will process a file sentence-by-sentence.

false

A sequence of coded instructions that manipulate data inside a computer

false

A while loop will always execute at least once.

false

A while loop will execute once for each expression in the conditional.

false

Dictionaries are useful because you can have duplicate keys.

false

Dictionaries will always have at least one key and one value.

false

Every function created with the def keyword must have AT LEAST ONE parameter.

false

Normally, statements are executed from top to bottom.

false

Once a function returns a variable, that variable is available outside of the function.

false

Printing is the same thing as returning.

false

Strings are composed of only letters and symbols.

false

The body of a for loop will contain one statement for each element of the iteration list.

false

The given program correctly closes 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")

false

The open function consumes a String representing a path and returns a String of the file's contents.

false

The print function can only print literal values.

false

The print function is necessary to call a function.

false

The statement count = count + 1 will cause an error because no number can be greater than itself.

false

Tuples are composed of key/value pairs.

false

Variable names are important because computers understand the meaning of names and change their value accordingly.

false

Variables in Python are used to solve for unknown values, like in Algebra.

false

You can nest if statements inside of other if statements, but not inside functions.

false

You should not put error messages into help seeking emails because it can clutter up the email.

false

A sequence of data stored in your computer's long term memory

file

A control structure for performing actions on each element of a sequence

for loop

A reusable chunk of code with inputs and outputs

function

A control structure for branching the execution of a program

if statement

Is the print call before, inside, or after the for loop? for name in names: print(name)

inside

def

keyword

for

keyword

import

keyword

in

keyword

return

keyword

while

keyword

label each of the following as a function call, method call, or not a call. function.call() print() file.(close) method() "function".method() (input)

method, function, not a call, function, method, not a call

A collection of functions, classes, and variables available to be imported

module

Which of the following expressions creates two new variables?

month, year = (11, 17)

A type that represents textual data

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?

string

Given this dictionary... animal = {"Name": "Pumpkin", "Age": 2, "Small?": True} ********** What is the type of the value associated with the key "Name"? *************** What is the type of the key "Name"? ************************* What is the type of the key "Small?"? ********************************** What is the type of the value associated with the key "Age"?

string, string, string, integer

Keys can be added to a dictionary after the dictionary has been created.

true

Like an if statement and a function call, the for Loop might cause the execution to not follow the sequential order of lines.

true

List comprehensions cannot express everything that a for loop can.

true

Normally, statements are executed from top to bottom.

true

The Iteration Variable will take on each value of the List Variable, one at a time.

true

Unlike Lists, Tuples are immutable, meaning Tuples cannot be changed after they are created.

true

Variables change their value over time according to the instructions in a program

true

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)

true

You can store a Dictionary as one of the elements of a List.

true

You can store a List as one of the values of a Dictionary.

true

You must import the json module before you can use the load function.

true

What types are sequences?

tuple, dictionary, string, list, file

A categorization of values of similar kinds that determines what you can do with the values.

type

boolean

type

dictionary

type

float

type

integer

type

list

type

string

type

""

value

[1:2]

value

[]

value

true

value

A name that can be associated with a value

variable


Conjuntos de estudio relacionados

projectiles, UCM, LUG exam - physics final

View Set

Microeconomics Exam 2 Study Guide

View Set

Ch 1: Operations & Supply Chain Mgmt

View Set

Unit 7 Vocab Synonyms and Antonyms

View Set

Strategic Management: Chapter 11

View Set

MASTERING BIOLOGY NATURAL SELECTION

View Set

Biology 1407: Labs 11-12 Predator-Prey, Diversity, Food Webs & Ecological Footprints

View Set

Linear Algebra Final Exam Study Guide

View Set