Python Programming Master Quiz

Ace your homework & exams now with Quizwiz!

In Python the ________ symbol is used as the not-equal-to operator

!=

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'

Which mathematical operator is used to raise 5 to the second power in Python?

**

Which method or operator can be used to concatenate lists?

+

What are the values that the variable num contains through the iterations of the following for loop? for num in range(4):

0, 1, 2, 3

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 def main(): num1 = 3 num2 = 4 answer = pass_it(num1, num2) print(answer) if __name__ == '__main__': main()

14

What is the output of the following command, given that value1 = 2.0 and value2 = 12? print(value1 * value2)

24.0

What will display after the following code is executed? def magic(num): answer = num + 2 * 10 return answer def main(): print( magic(5) ) if __name__ == '__main__': main()

25

What is the largest value that can be stored in one byte?

255

What will be displayed after the following code is executed? for num in range (0, 20, 5): num += num print(num)

30

What will be displayed after the following code is executed? total = 0 for count in range(4,6): total += count print(total)

4 9

What will be displayed after the following code is executed? total = 0 for count in range(1,4): total += count print(total)

6

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

64

After the execution of the following statement, the variable price will reference the value ________ price = int(68.549)

68

What is the decimal value of the following binary number? 1001

9

In Python the ________ symbol is used as the equality operator

==

The ________ coding scheme contains a set of 128 numeric codes that are used to represent characters in the computer's memory

ASCII

Which computer language uses short words known as mnemonics for writing programs?

Assembly

Which language is referred to as a low-level language? a. Python b. Java c. Assembly language d. C++

Assembly Language

Which of the following is not a microprocessor manufacturing company? a. Motorola b. Dell c.Intel d. AMD

Dell

Which of the following is considered to be the world's first programmable electronic computer?

ENIAC

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 print(average) 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

A function definition specifies what a function does and causes the function to execute.

False

A list cannot be passed as an argument to a function.

False

A local variable can be accessed from anywhere in the program.

False

A mutator method has no control over the way that a class's data attributes are modified.

False

All instances of a class share the same values of the data attributes in the class.

False

An object is a stand-alone program but is used by programs that need its service.

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.

False

In Python, an infinite loop usually occurs when the computer accesses an incorrect memory address.

False

In Python, math expressions are always evaluated from left to right, no matter what the operators are

False

In a UML diagram the first section holds the list of the class's methods.

False

One of the drawbacks of a modularized program is that the only structure you can use in such a program is the sequence structure.

False

Python allows you to compare strings, but it is not case sensitive

False

Python uses the same symbols for the assignment operator as for the equality operator

False

The index of the first element in a list is 1, the index of the second element is 2, and so forth.

False

The sort method rearranges the elements of a list so they are in ascending or descending order.

False

To get the total number of iterations in a nested loop, add the number of iterations in the inner loop to the number in the outer loop.

False

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

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

The acronym ________ refers to the fact that the computer cannot tell the difference between good data and bad data.

GIGO

Procedures operate on data items that are separate from the procedures.

GUESS

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 print(average) except ZeroDivisionError: print('ERROR: cannot have 0 items') except ValueError: print('ERROR: number of items cannot be negative') if __name__ == '__main__': main()

GUESS. NOT: ERROR: number of items can't be negative

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

Gaddis, Tony

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

I'm ready to begin

The ________ chart is an effective tool used by programmers to design and document functions.

IPO

________ is the process of inspecting data that has been input into a program in order to ensure that the data is valid before it is used in a computation.

Input validation

Select all that apply. Assume you are writing a program that calculates a user's total order cost that includes sales tax of 6.5%. Which of the following are advantages of using a named constant to represent the sales tax instead of simply entering 0.065 each time the tax is required in the code?

It will be easier for another programmer who may need to use this code to understand the purpose of the number wherever it is used in the code. If the tax amount changes to 7.0%, the value will only have to be changed in one place. It avoids the risk that any change to the value of sales tax will be made incorrectly or that an instance of the tax value might be missed as might occur if the number had to be changed in multiple locations.

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

None

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

Processing a tuple is faster than processing a list.

Main memory is commonly known as ________

RAM

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.

What is the output of the following print statement? print('The path is D:\\sample\\test.')

The path is D:\sample\test.

A class can be thought of as a blueprint that can be used to create an object.

True

A flowchart is a tool used by programmers to design programs

True

A software developer is the person with the training to design, create, and test computer programs

True

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

True

Closing a file disconnects the communication between the file and the program.

True

Comments in Python begin with the # character

True

Different functions can have local variables with the same names.

True

If the last line in a file is not terminated with \n, the readline method will return the line without \n.

True

In a flowchart, both the decision structure and the repetition structure use the diamond symbol to represent the condition that is tested.

True

In a nested loop, the inner loop goes through all of its iterations for each iteration of the outer loop.

True

It is possible to create a while loop that determines when the end of a file has been reached.

True

Lists are dynamic data structures such that items may be added to them or removed from them.

True

Nested decision statements are one way to test more than one condition

True

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

True

One reason not to use global variables is that it makes a program hard to debug.

True

RAM is a volatile memory used for temporary storage while a program is running

True

Reducing duplication of code is one of the advantages of using a loop structure.

True

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

The ZeroDivisionError exception is raised when the program attempts to perform the calculation x/y if y = 0.

True

The index -1 identifies the last element in a list.

True

The integrity of a program's output is only as good as the integrity of its input. For this reason, the program should discard input that is invalid and prompt the user to enter valid data.

True

The main reason to use secondary storage is to hold data for long periods of time, even when the power supply to the computer is turned off

True

The self parameter is required in every method of a class.

True

The self parameter need not be named self but it is strongly recommended to do so, to conform with standard practice.

True

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

True

When using the camelCase naming convention, the first word of the variable name is written in lowercase and the first characters of all subsequent words are written in uppercase

True

A Boolean variable can reference one of two values which are

True or False

________ provides a set of standard diagrams for graphically depicting object-oriented systems.

UML

What does the acronym UML stand for?

Unified Modeling Language

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

[0, 2, 4, 6, 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]

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

[1, 2, 3]

The line continuation character is a

\

Which method is automatically executed when an instance of a class is created in memory?

__init__

What is the special name given to the method that returns a string containing an object's state?

__str__

Which method is automatically called when you pass an object as an argument to the print function?

__str__

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

a quote mark (")

When an object is passed as an argument, ________ is passed into the parameter variable.

a reference to the object

Select all that apply. To create a Python program you can use - a text editor - Excel - a word processor if you save your - file as a .docx - IDLE

a text editor; IDLE

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

a try/except statement

A method that returns a value from a class's attribute but does not change it is known as a(n) ________ method.

accessor

What type of method provides a safe way for code outside a class to retrieve the values of attributes, without exposing the attributes in a way that could allow them to be changed by code outside the method?

accessor

Which of the following can be thought of as a self-contained unit that consists of data attributes and the methods that operate on the data attributes?

an object

When using the ________ logical operator, both subexpressions must be true for the compound expression to be true

and

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

argument

A(n) ________ file contains data that has not been converted to text.

binary

The smallest storage location in a computer's memory is known as a

bit

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

block

A(n) ________ is code that specifies the data attributes and methods for a particular type of object.

class

Which is the first line needed when creating a class named Worker?

class Worker:

A(n) ________ expression is made up of two or more Boolean expressions

compound

Multiple Boolean expressions can be combined by using a logical operator to create ________ expressions

compound

When the + operator is used with two strings, it performs string ________

concatenation

What type of loop structure repeats the code based on the value of Boolean expression?

condition-controlled loop

In a decision structure, the action is ________ executed because it is performed only when a specific condition is true

conditionally

A(n) ________ structure is a logical design that controls the order in which a set of statements execute

control

What type of loop structure repeats the code a specific number of times?

count-controlled loop

What will be displayed after the following code is executed? count = 4 while count < 12: print("counting") count = count + 2

counting counting counting counting

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')

The function header begins with the keyword ________ and is followed by the name of the function.

def

A class ________ is a set of statements that defines a class's methods and data attributes.

definition

In flowcharting, the ________ symbol is used to represent a Boolean expression

diamond

What are the data items in a list called?

elements

Combining data and code in a single object is known as

encapsulation

A(n) ________ character is a special character that is preceded with a backslash (\), appearing inside a string literal

escape

When a function is called by its name during the execution of a program, then it is

executed

A filename ________ is a short sequence of characters that appear at the end of a filename, preceded by a period.

extension

The process known as the ________ cycle is used by the CPU to execute instructions in a program

fetch-decode-execute

A single piece of data within a record is called a

field

When a program needs to save data for later use, it writes the data in a(n) ________.

file

Boolean variables are commonly used as ________ to indicate whether a specific condition exists

flags

After the execution of the following statement, the variable sold will reference the numeric literal value as (n) ________ data type sold = 256.752

float

A(n) ________ is a diagram that graphically depicts the steps that take place in a program?

flowchart

In Python, you would use the ________ statement to write a count-controlled loop.

for

Accessor methods are also known as

getters

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

global

A ________ variable is accessible to all the functions in a program file.

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

In object-oriented programming, one of first tasks of the programmer is to

identify the classes needed

Which of the following is the correct if clause to determine whether choice is anything other than 10? a. if not(choice < 10 and choice > 10): b. if choice != 10: c. if choice <> 10: d. if choice != 10

if choice != 10:

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

if y >= 10 and y <= 50:

Python provides a special version of a decision structure known as the ________ statement, which makes the logic of the nested decision structure simpler to write

if-elif-else

A(n) ________ statement will execute one block of statements if its condition is true or another block if its condition is false

if-else

Tuples are ________ sequences which means that once a tuple is created, it cannot be changed.

immutable

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

import random

Each element in a tuple has a(n) ________ that specifies its position in the tuple.

index

A(n) ________ loop usually occurs when the programmer does not include code inside the loop that makes the test condition false.

infinite

A(n) ________ method in a class initializes an object's data attributes.

initializer

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

input ( )

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

insert

Each object that is created from a class is called a(n) ________ of the class.

instance

Which attributes belong to a specific instance of a class?

instance

The built-in function ________ returns the length of a sequence.

len Function

In Python, a comma-separated sequence of data items that are enclosed in a set of brackets is called

list

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

list

A ________ variable is created inside a function.

local

The following is an example of an instruction written in which computer language? 10110000 a. machine language b. C# c. Java d. Assembly language

machine language

The disk drive is a secondary storage device that stores data by ________ encoding it onto a spinning circular disk

magnetically

Where does a computer store a program and the data that the program is working with while the program is running?

main memory

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

math

The procedures that an object performs are called

methods

Functions that are in the standard library are stored in files that are known as ________.

modules

The % symbol is the remainder operator, also known as the ________ operator

modulo

Lists are ________, which means their elements can be changed in a program.

mutable

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

nested list

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

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

The logical ________ operator reverses the truth of a Boolean expression

not

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

number = random.randint (1, 50)

In ________ programming, the programming is centered on objects that are created from abstract data types that encapsulate data and functions together.

object-oriented

What type of programming contains class definitions?

object-oriented

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

In the expression 12.45 + 3.6, the values to the right and left of the + symbol are the ________

operands

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

or

Which logical operators perform short-circuit evaluation?

or, and

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

________ programming is a method of writing software that centers on the actions that take place in a program.

procedural

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?

pseudocode

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

The ________ function is a built-in function that generates a list of integer values.

range

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 flowchart, a function call is depicted by a(n) ________.

rectangle

A(n) ________ structure is a structure that causes a statement or a set of statements to execute repeatedly.

repetition

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

A variable is available only to statements in the variable's ________.

scope

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

scope

In ________ mode, the interpreter reads the contents of a file that contains Python statements and executes each statement

script

Which section in the UML holds the list of the class's data attributes?

second section

The instance attributes are created by the ________ parameter and they belong to a specific instance of the class.

self

A(n) ________ is a special value that marks the end of a sequence of items.

sentinel

A(n) ________ access file retrieves data from the beginning of the file to the end of the file.

sequential

Mutator methods are also known as

setters

A(n) ________ is a span of items that are taken from a sequence.

slice

A ________ has no moving parts and operates faster than a traditional disk drive

solid state drive

An object's ________ contains the values of the object's attributes at a given moment.

state

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

str

Which type of error prevents the program from running?

syntax

In Python, the variable in the for clause is referred to as the ________ because it is the target of an assignment at the beginning of each loop iteration.

target variable

Select all that apply. Which of the following are steps in the program development cycle? - test the program - write the code and correct syntax errors - design the program - correct logic errors

test the program; write the code and correct syntax errors; design the program; correct logic errors

A(n) ________ file contains data that has been encoded as text, using a scheme such as ASCII.

text

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 section in the UML holds the list of the class's methods?

third section

The ________ design technique can be used to break down an algorithm into functions.

top-down

Which of the following represents an example to calculate the sum of numbers (that is, an accumulator), given that the number is stored in the variable number and the total is stored in the variable total? total += number number += number total = number total + number = total

total += number

A(n) ________ gives information about the line number(s) that caused an exception.

traceback

A(n) ________ block includes one or more statements that can potentially raise an exception.

try block

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

tuple

How many types of files are there?

two

The encoding technique used to store negative numbers in the computer's memory is called

two's complement

Which of the following will create an object, worker_joey, of the Worker class?

worker_joey = Worker()

What does the following expression mean? x <= y

x is less than or equal to y


Related study sets

PHS AP Euro Unit 12 Ch. 13 - Mass Society in an "Age of Progress"

View Set

psy chapter 11: social development relationships and roles

View Set

Ch12: Reporting Cash Flows ACCT 211

View Set

ATI Pharmacology Made Easy 4.0 ~ The Neurological System (Part 2)

View Set

数学(中学三年生)平方根

View Set