Programming Quizes 6 & 4

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

Which mode specifier will erase the contents of a file if it already exists and create the file if it does not already exist? A. 'w' B. 'r' C. 'a' D. 'e'

A. 'w'

Which of the following describes what happens when a piece of data is written to a file? Select one: A. The data is copied from a variable in RAM to a file. B. The data is copied from a variable in the program to a file. C. The data is copied from the program to a file. D. The data is copied from a file object to a file.

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

What does the following statement represent?number1, number2 = GetInput() Select one: A. The function GetInput() is expected to return a value for number1 and for number2. B. The function GetInput() is expected to return one value and assign it to number1 and number2. C. This statement will cause a syntax error. D. The function GetInput() will receive the values stored in number1 and number2.

A. The function GetInput() is expected to return a value for number1 and for number2.

Our textbook defines a _________ as a group of statements that exists within a program for the purpose of performing a specific task? Select one: A. a function B. a subtask C. a process D. a subprocess

A. a function

The first line in a function definition is known as the function (an example is below) _______?def GetInput(var1, var2): Select one: A. header B. block C. return D. parameter

A. header

Which step creates a connection between a file and a program? Select one: A. open the file B. read the file C. process the file D. close the file

A. open the file

Which type of file do you access data from the beginning of the file to the end of the file and if you want to read a piece of data that is stored at the very end of the file, you have to read all of the data that comes before it—you cannot jump directly to the desired data. Select one: A. sequential B. random C. numbered D. text

A. sequential

Which method could be used to convert a numeric value to a string? A. str B. value C. num D. chr

A. str

Which mode specifier will open a file but not let you change the file or write to it? Select one: A. 'w' B. 'r' C. 'a' D. 'e'

B. 'r'

What will be displayed after the following code is executed?def Main():result = 0 number1 = 4number2 = 5result = GetNum(number1, number2)print(result)def GetNum(a, b):c = 0c = a*bresult = Answer(c)return(result)def Answer(number):z = 0 z = number + 2 return(z)Main() Select one: A. 28 B. 22 C. 14 D. Nothing, this code contains a syntax error.

B. 22

If a file with the specified name already exists when the file is opened and the file is opened in 'a' mode, then an alert will appear on the screen. A. True B. False

B. False

def main():print("The output to the problem is:", GetOutput(5))def GetOutput(number):output = 0 output = number + 2 * 10return outputmain() Select one: A. The output to the problem is: 70 B. The output to the problem is: 25 C. The output to the problem is: 100 D. This is not valid code.

B. The output to the problem is: 25

When a function is called within a program, items that are passed to the function inside parentheses are called? Select one: A. global variable B. argument C. local variable D. parameter

B. argument

An attempt to open a nonexistent file for input: A. generates syntax error B. generates runtime error C. generates logical error D. creates a new file for the program

B. generates runtime error

________ variables in a program, should be used only when necessary because, they make a program harder to debug and use memory as long as the program is running. Select one: A. local B. global C. string D. float

B. global

Which method could be used to strip specific characters from the end of a string? Select one: A. estrip B. rstrip C. strip D. remove

B. rstrip

How many types of files are there? A. one (text) B. two (text and binary) C. three (text, binary, numeric) D. All types

B. two (text and binary)

A value-returning function is Select one: A. a single statement that performs a specific task B. called when you want the function to stop C. a function that will return a value back to the part of the program that called it D. a function that receives a value when called

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

An exception is an error that occurs while a program is running, causing the program to abruptly halt. You can use the ___________ statement to gracefully handle exceptions. Select one: A. an exception statement B. a try statement C. a try/except statement D. an exception handler statement

C. a try/except statement

A single piece of data within a record is called a Select one: A. variable B. delimiter C. field D. data bit

C. field

When a variable is declared outside of all functions in a program file it is called a _________ variable. These variable can also be sued by any function in the program without being passed as arguments to a function. Select one: A. keyword B. local C. global D. string

C. global

Which of the following is the correct way to open a file named customers.txt in 'r' mode using a file variable called infile? A. infile = open('r', customers.txt) B. infile = read('customers.txt', 'r') C. infile = open('customers.txt', 'r') D. infile = readlines('customers.txt', r)

C. infile = open('customers.txt', 'r')

Which of the following is the correct way to open a file named customers.txt to write to it, using a file variable called outfile, but keeping the existing data and adding data to the file? Select one: A. outfile = open(customers.txt, 'w') B. outfile = write('customers.txt', 'w') C. outfile = open('customers.txt', 'a') D. outfile = write('customers.txt', 'a')

C. outfile = open('customers.txt', 'a')

What will be the output after the following code is executed?def Main():firstName = "Tony"lastName = "Gaddis"fullName = ""fullName = Find(firstName, lastName)print(fullName)def Find(b, c):a = "" a = c + ", " + breturn(a)Main() Select one: A. Tony Gaddis B. Gaddis Tony C. Tony, Gaddis D. Gaddis, Tony

D. Gaddis, Tony

What is the process of saving data to a file called? A. retrieving B. reading C. appending D. writing

D. Writing

Given that the customerFile variable 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? Select one: A. customer File.write('Mary Smith') B. customerFile.write('w', 'Mary Smith') C. customerFile.input('Mary Smith') D. customerFile.write('Mary Smith')

D. customerFile.write('Mary Smith')

A file object is associated with a _________ in a program to carry out any operations that are performed on the file. A. filename B. file extension C. file path D. file variable

D. file Variable

In the function heading, variables that accepts an argument passed by the function call are called ____________. Select one: A. global variables B. arguments C. named constants D. parameters

D. parameters

Which method will return an empty string when it has attempted to read beyond the end of a file? Select one: A. read B. getline C. input D. readline

D. readline

A variable's ________ is the part of a program in which the variable may be accessed and therefore, the ________ of a local variable is the function in which that variable is created. Select one: A. global reach B. definition C. space D. scope

D. scope

The ZeroDivisionError exception is raised when the program attempts to perform the calculation x/y if x = 0. Select one: True False

False

According to our textbook which function naming rule below is not valid? Select one: a. Uppercase and lowercase characters are distinct in a function name b. A function name cannot contain spaces c. You cannot use one of Python's key words as a function name d. The first character must be one of the letters a through z, A through Z, or a digit 0 through 9

The first character must be one of the letters a through z, A through Z, or a digit 0 through 9

If a variable called lastName is created in one function and the same variable name is used for a variable in another function what will be the outcome? Select one: a. They will create no conflict with each other b. They create a conflict with each other c. They must be declared to be global d. They cause a Traceback error

a. They will create no conflict with each other

In Python, a function header always ends with a? Select one: a. colon b. semicolon c. ending parentheses d. period

a. colon

Python allows a programmer to pass __________ arguments. These arguments specify in the function call argument the name of a parameter variable in the function header and the value being passed to that parameter. Select one: a. keyword b. positional c. value d. reference

a. keyword

A ________is simply a named file that contains Python code that consist of functions that perform related tasks. The file must end with the .py ending and the functions in the named file can be utilized in another Python program by using the keyword "import" with the file name. Select one: a. module b. procedure c. unit d. segment

a. module

Which standard library module do you need to import in order to use the remove and rename functions for files? Select one: a. os b. fstream c. file d. iomanip

a. os

The data that is stored in a file is frequently organized in __________ which is a complete set of data about an item. Such as a file may contain complete data about an employee including name, address, pay rate etc. Select one: a. records b. raw data c. strings d. sequential

a. records

After all the lines of a file have been read, the readline method returns __________. Select one: a. An Error b. An empty string c. An exception d. The last piece of data in the file

b. An empty string

If a Main function calls another function. What happens to a variable declared locally inside the called function after the function terminates and control returns to the Main function? Select one: a. It maintains its value even after the function ends and control goes back to the Main function b. It ceases to exist after the function ends and control goes back to the Main function c. It loses its value temporarily after the function ends and control goes back to the Main function but, regains that value upon re-entry if the function is called again d. Is reset to the null value

b. It ceases to exist after the function ends and control goes back to the Main function

In a function call, positional arguments and the matching parameters in the function header must _______ Select one: a. Match in name of the arguments to the name in the parameter b. Match in number of arguments to number of parameters c. Match in name and number of the arguments to the name and number of the parameters d. There are no set rules

b. Match in number of arguments to number of parameters

According to our textbook, what is the rule in a function call when passing positional arguments and keyword arguments to the function header/definition? Select one: a. There is no rule b. Positional arguments must be stated before keyword arguments c. Keyword arguments must be stated first before positional arguments d. As long as they match in order and number it does not matter which are stated first

b. Positional arguments must be stated before keyword arguments

When a called function ends execution of the program jumps to Select one: a. The statement before the statement that called the function b. The statement after the statement that called the function c. The beginning of the function containing the calling statement d. The end of the function containing the calling statement.

b. The statement after the statement that called the function

Of the following, which one would NOT be a reason for utilizing functions in a program? Select one: a. They break a complex problem down into smaller pieces. b. They make a program run faster. c. They can be reused easily. d. They make it easier for a team of people to work together on a single program.

b. They make a program run faster.

Python, and most programming languages, , comes with standard library modules of functions that have already been written for you. To gain access to the functions and variables of a library module, use a(n) _________ statement. Select one: a. print b. import c. export d. global

b. import

What will be the output of the following lines of code? def Main(): num1 = 0.0 num2 = 0.0 num3 = 0.0 num1 = 4.5 num2 = 6.75 num3 = 1 TruncateSum(num1, num2, num3) def TruncateSum(var1, var2, var3): print(int(var1 + var2 + var3)) Main() Select one: a. 12.25 b. 13 c. 12 d. 12.0

c. 12

A variable created inside a function is called a _________ variable. Select one: a. Global b. Inner c. Local d. Return

c. Local

What is wrong with the following calling statement and its corresponding Sub statement? MyProcedure("The Jetsons", 1000, 209.53) def MyProcedure(var1, var2, var3, var4): Select one: a. It is not valid to pass something like "The Jetsons." b. Constant values like 1000 cannot be passed, only variables. c. There is a mismatch between arguments passed in the function call and variables accepted in the parameters of the function heading d. There is nothing wrong. It is valid code.

c. There is a mismatch between arguments passed in the function call and variables accepted in the parameters of the function heading

A function definition specifies what a function does, but it does not cause the function to execute. To execute a function, you must use a function _____. Select one: a. header b. run c. call d. search

c. call

What function do you use to terminate a connection to a file? Select one: a. end b. stop c. close d. disconnect

c. close

The purpose of using a readline method just before entering a while loop is to get the first line in the file, so it can be tested by the loop. This initial read operation is called a ______ read. Select one: a. initial b. start c. priming d. beginning

c. priming

Our textbook references how many modes for opening a file (there are other complex modes but are book focused on how many)? Select one: a. One b. two c. three d. four

c. three

The two types of user defined functions are? Select one: a. void and value b. void-returning & value c. value-returning & void d. void & void-returning

c. value-returning & void

This type of function, according to our textbook, simply executes the statements it contains and then terminates. Select one: a. value-returning b. standard c. void d. predetermined

c. void

What is the following output? def Main(): x = 5 y = 10 x = 5 y = 10 x = Swap(x, y) print(x, y) def Swap(x, y): temp = 0 temp = x x = y y = temp return x Main() Select one: a. 5 5 b. 5 10 c. 10 5 d. 10 10

d. 10 10


संबंधित स्टडी सेट्स

PN Adult Medical Surgical Online Practice 2020 B

View Set

Chapter 10: Emotional Development and Attachment

View Set

Florida statues, rules, and regulations common to all lines

View Set

Which Chinese Measure Word to Use?

View Set

Physical Science Chap. 6 Thermal

View Set