CSC 121 Final

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

Try

A ____ block includes one or more statements that could raise an exception.

Variable

A ____ is a name that represents a value stored in computer memory

argument

A ____ is any piece of data that is passed into a function when the function is called.

local

A _____ variable is created within a function

false

A function definition specifies what a function does and causes the function to execute. True or false?

False

A list cannot be passed as an arg to a function. True or false?

block

A set of statements that belong together as a group and contribute to the function definition is known as a ____

a function that will return a value back to the part of the program that called it

A value-returning function is what?

return

A value-returning statement has a _____ statement that sends a value back to the part of the program that called it

Float

After the execution of the following statement, the variable *sold* will reference the numeric literal value as a ____ data type. sold = 256.752

True

Closing a file disconnects the communication between the file and the program. True or false?

True

Comments in Python begin with #. True or false?

True

Computer programs typically perform 3 steps: Input, Processing input, and output. True or false?

True

Different functions can have local variables with the same names. True or false?

customer.write('Mary Smith')

Given that the customer file references a file object, and the file was opened using the 'w' mode specifier, how would you write the string 'Mary Smith' to the file?

Reformat Code

In PyCharm, What feature will alter a code file so that it conforms to the python.org PEP8 coding style?

import matplotlib.pyplot

In order to create a graph in Python, you need to include

operands

In the expression 12 + 7, the values on the right and left of the + symbol are called

True

Indexing works in both strings and lists. True or false?

True

Invalid indexes do not cause slicing expressions to raise an exception. True or false?

global

It is recommended programmers avoid using _____ variables whenever possible

False

Python allows you to compare strings, but is NOT case sensitive. True or false?

False

Python formats all floating point numbers to 2 decimal places when outputting with the print statement?

False

Python is not sensitive to block of structuring of code. True or false?

False

Python uses the same symbols for the assignment operator as for the equality operator. True or false?

randrange

Returns a random value from the sequence indicated by the arguments

modulus

The % symbol is the remainder operator, also known as _____.

True

The -1 index identifies the last character in a string. True or false?

True

The -1 index represents the last element in a list. True or false?

False

The Python language uses a compiler, which is a program that both translates and executes the instructions in a high-level language. True or false?

tuple

The ____ function can be used to convert a list to a tuple.

input()

The ____ function reads a piece of data that has been entered at the keyboard and returns that piece of data, as a string, back to the program.

keys

The ________ method returns all of a dictionary's keys as a dictionary view.

len

The built in __ function returns the length of a sequence

False

The first element in a list is 1, the second is 2, and so on. True or false?

False

The following code will display 'yes + no', true or false?: mystr = 'yes' yourstr = 'no' mystr += yourstr print(mystr)

false

The following string is valid. string[i]='i' True or false?

True

The if statement causes one or more statements to execute only when a boolean expression is true. True or false?

not

The logical _____ operator reverses the truth of a boolean expression

once a tuple is created, it cannot be changed

The primary difference between a tuple and a list is that

False

The remove method removes all occurrences of an item from a list. True or false?

True

To calculate the To calculate the average of the numeric values in a list, the first step is to get the total of values in the list. True or false?

dump, pickle

To write an object to a file, you use the ________ function of the ________ module.

True

True or False: Strings can be written directly to a file with the write method, but numbers must be converted to strings before they can be written.

True

True or false: An exception handler is a piece of code that is written using the try/except statement.

False

True or false: If a file with the specified name already exists when the file is opened and the file is opened in 'w' mode, then an alert will appear on the screen.

True

True or false: Object-oriented programming allows us to hide the object's data attributes from code that is outside the object.

Elements

What are data items in a list called?

Processing a tuple is faster than processing a list.

What is an advantage of using a tuple rather than a list?

if choice != 10

What is the correct if clause to determine whether choice is anything other than 10?

list1 = [] for x in range(3): for y in range(2): if (x + y ) % 2 == 0: list1.append([x,y])

What is the equivalent code for the following list comprehension? list1 =[[x,y] for x in range(3) for y in range(2) if (x + y) % 2 == 0]

Pseudocode

What is the informal language, used by programmers use to create models of programs, that has no syntax rules and is not meant to be compiled or executed?

list1 = [4, 7, 12, 8, 25] list2 = [x*2 for x in list1 if x > 10]

What is the list compression for the following? list1 = [4, 7, 12, 8, 25] list2 = [] for x in list1: if x > 10: list2.append(x*2)

I'm ready to begin

What is the output of the following print statement? print 'I\' m ready to begin'

Reading data

What is the process of retrieving data from a file called?

picling

What is the process used to convert an object to a stream of bytes that can be saved in a file?

False

What is the result of the following Boolean expression, given that x = 5, y = 3, and z= 8? not (x < y or z > x) and y < z

False

What is the result of the following boolean expression given that x=5, y=3, and z=8? not (x < y or z > x) and y < z

False

What is the result of the following boolean expression given that x=5, y=3, and z=8? x < y and z > x

True

What is the result of the following boolean expression given that x=5, y=3, and z=8? x < y or z > x

['03', '07', '2018']

What list will be referenced by the variable list_strip after the following code executes? my_string = '03/07/2018' list_strip = my_string.split('/')

[0, 2, 4, 6, 8]

What list will be referenced by the variable number after the following code is executed? number = range(0, 9, 2)

wb

What mode do you use with the open function to open a binary file for writing?

|

What operator was introduced in Python 3.9 that performs a dictionary merge?

a del statement

What statement would you use if an element needs to be removed from a specific index?

A quote mark (")

What symbol is used to mark the begging and end of a string?

'1357'

What will be assigned to the variable s_string after the following code executes? special = '1357 Country Ln.' s_string = special[ :4]

'Ln.'

What will be assigned to the variable s_string after the following code executes? special = '1357 Country Ln.' s_string = special[-3:]

yesnono

What will be displayed after the following code executes? mystr = 'yes' yourstr = 'no' mystr += yourstr * 2 print(mystr)

14

What will be displayed after the following code is executed? def pass_it(x, y): z = x*y result = get_result(z) return(result) def get_result(number): z = number + 2 return(z) num1 = 3 num2 = 4 answer = pass_it(num1, num2) print(answer)

Gaddis, Tony

What will be the output after the following code is executed? def pass_it(x, y): z = x + ", " + y return(z) name2 = "Tony" name1 = "Gaddis" fullname = pass_it(name1, name2) print(fullname)

[1, 2, 3, 10]

What will be the value of the variable list after the following code executes? list = [1, 2, 3, 4] list[3] = 10

[1, 2, 1, 2, 1, 2]

What will be the value of the variable list after the following code executes? list = [1, 2] list = list * 3

'Hello World!'

What will be the value of the variable string after the following code executes? string = 'Hello' string += ' world!'

Invalid, must contain one number.

What will display after the following code executes? password = 'ILOVEPYTHON' if password.isalpha(): print('Invalid, must contain one number.') elif password.isdigit(): print('Invalid, must have one non-numeric character.') elif password.isupper(): print('Invalid, cannot be all uppercase characters.') else: print('Your password is secure!')

Output

When data is written to a file, it is described as an _____ file.

concatenation

When the + operator is used with 2 strings, it performs _____.

{'IBM':143, 'HPQ':29, 'MSFT':288}

When the following code executes, what values will be in the stocks2 dictionary? stocks1 = {'GOOGL':2708, 'AAPL':147, 'MSFT':288} stocks2 = {'IBM':143, 'HPQ':29, 'MSFT':288} stocks1 |= stocks2

or

When using the ____ logical operator, one or both of the subexpressions must be true for the compound expression to be true.

and

When using the logical _____ operator, both subexpressions must be true for the compound to be true.

nested list

When working with multiple sets of data, one would typically use a(n)

str

Which method could be used to convert a numeric value to a string?

find(substring)

Which method would you use to determine wether a certain substring is present in a string?

Items

Which method would you use to get all the elements in a dictionary returned as a list of tuples?

'r'

Which mode specifier will open a file but not let you change the file or write to it?

All of the above

Which of the following are steps in the development process? write the code and correct syntax errors correct logic errors design the program test the program

if y >= 10 and y <= 50

Which of the following is the correct if clause to determine whether y is in the range 10 through 50, inclusive?

outfile = open('users.txt', 'w')

Which of the following is the correct way to open a file named users.txt to write to it?

import random

Which of the following statements causes the interpreter to load the contents of the random directory into memory?

Open the file

Which step creates a connection between a file and a program?

False

You cannot use a for loop to iterate through a string. True or false?

cubes = {} for x in range(5): cubes[x] = x ** 3

cubes = {x: x**3 for x in range(5)} What code is equivalent to this dictionary comprehension?

seed

initializes the formula used by the random module to generate random modules

random

returns a random float between 0.0 and 1.0

uniform

returns a random float in the specified range

randint

returns a random number from among the numbers between the two arguments

squ_dict = {x: x**2 for x in range(10) if x % 2 == 0}

squ_dict = {} for x in range(10): if x % 2 == 0: squ_dict[x] = x ** 2 What is the equivalent dictionary comprehension of the above code?

station_names = list(stations.values())

stations = {89.7:'WCPE', 91.5:'UNCW', 92.3:'WKRR', 92.5:'WYFL'} How could you create a list of the values from stations and assign it to station_names?

append

the ____ method is commonly used to add items to a list

immutable

tuples are _____ sequences, meaning that once it is created, it cannot be changed


Ensembles d'études connexes

Корейский для детей 1-1 Урок 14-1

View Set

Chapter 15: Psychological Disorders

View Set

Chapter 12.2.7 Practice Questions

View Set

VNSG 1304: Ch. 1 Prep U Questions

View Set

week 5 eaq and week 7 Professional Identity

View Set

WORD PROBLEMS (The answers are my own words and solutions. It is your choice to believe it or not. Hahahaha)

View Set

Organizational Behavior MC Questions Chapter 1-12

View Set