CIS 202 Ch.5-7

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

What will be the output after the following code is executed? def pass_it(x, y): z = x , ", " , y num1 = 4 num2 = 8 answer=pass_it(num1,num2) print(answer)

None

What will be the value of the variable list2 after the following code executes? list1 = [1, 2, 3] list2 = [] for element in list1: list2.append(element) list1 = [4, 5, 6]

[1, 2, 3]

What values will list2 contain after the following code executes? list1 = [1, 2, 3] list2 = [item + 1 for item in list1]

[2, 3, 4]

What values will list2 contain after the following code executes? list1 = [1, 10, 3, 6] list2 = [item * 2 for item in list1 if item > 5]

[20, 12]

Which of the following would you use if an element is to be removed from a specific index?

a del statement

A value-returning function is

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

Which statement can be used to handle some of the runtime errors in a program?

a try/except statement

A single piece of data within a record is called a

field

Which of the following functions returns the largest integer that is less than or equal to its argument?

floor

A __________ constant is a name that references a value that cannot be changed while the program runs.

global

It is recommended that programmers avoid using __________ variables in a program whenever possible

global

The first line in a function definition is known as the function

header

Whic of the following will assign a random integer in the range of 1 through 50 to the variable number?

number= random.randint(1,50)

The primary difference between a tuple and a list is that

once a tuple is created, it cannot be changed

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

open the file

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

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

A(n) __________ is a variable that receives an argument that is passed into a function.

parameter

The _____________ keyword is ignored by the Python interpreter and can be used as a placeholder for code that will be written later.

pass

A(n) __________ access file is also known as a direct access file.

random

Which type of file access jumps directly to a piece of data in the file without having to read all the data that comes before it?

random

When a file has been opened using the 'r' mode specifier, which method will return the file's contents as a string?

read

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

reading data

Which method will return an empty string when it has attempted to read beyond the end of a file?

readline

In a value-returning function, the value of the expression that follows the keyword __________ will be sent back to the part of the program that called the function.

return

Which method could be used to strip specific characters from the end of a string?

rstrip

The __________ of a local variable is the function in which that variable is created

scope

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

str

Which method or operator can be used to concatenate lists?

+

What is the first negative index in a list?

-1

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

64

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

'r'

Which mode specifier will erase the contents of a file if it already exists and create the file if it does not already exist?

'w'

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)

14

What will display after the following code is executed? def main(): print("The answer is", magic(5)) def magic(num): answer = num + 2 * 10 return answer main()

25

What will be the output after the following code is executed and the user enters 75 and 0 at the first two prompts? def main(): try: total = int(input("Enter total cost of items? ")) num_items = int(input("Number of items ")) average=total/num_items except ZeroDivisionError: ............print('ERROR: cannot have 0 items') except ValueError: print('ERROR: number of items cannot be negative') if __name__ == '__main__': main()

ERROR: cannot have 0 items

What will be the output after the following code is executed and the user enters 75 and -5 at the first two prompts? def main(): try: total = int(input("Enter total cost of items? ")) num_items = int(input("Number of items ")) average=total/num_items except ZeroDivisionError: ........print('ERROR: cannot have 0 items') except ValueError: print('ERROR: number of items cannot be negative') if __name__ == '__main__': main()

Nothing; there is no print statement to display average. The ValueError will not catch the error.

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

Processing a tuple is faster than processing a list.

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

Smith, Julian

Which of the following describes what happens when a piece of data is written to a file?

The data is copied from a variable in RAM to a file.

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

[0, 2, 4, 5, 8]

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

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

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

[1, 2, 3, 10]

A(n) __________ is any piece of data that is passed into a function when the function is called.

argument

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

block

This function in the random module returns a random element from a list.

choice

This function in the random module returns multiple, nonduplicated random elements from a list.

choices

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?

customer.write('Mary Smith')

What are the data items in a list called?

elements

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

import random

Which of the following is the correct way to open a file named users.txt in 'r' mode?

infile = open('users.txt', 'r')

Which method can be used to place an item at a specific index in a list?

insert

Which method can be used to convert a tuple to a list?

list

A __________ variable is created inside a function.

local

The Python standard library's __________ module contains numerous functions that can be used in mathematical calculations.

math

Which of the following is associated with a specific file and provides a way for the program to work with that file?

the file object

Which method can be used to convert a list to a tuple?

tuple


Ensembles d'études connexes

CH. 34 PEDIATRIC EMERGENCIES (NEW)

View Set

Chapter 16 book questions + answers

View Set

Computer Science Lesson 1-7 Questions

View Set

Formulas For Area and Perimeter of Shapes

View Set

Pharmacology and Medication Management

View Set