business programming

Ace your homework & exams now with Quizwiz!

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 mathematical operator is used to raise 5 to the second power in Python?

**

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 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 main(): print("The answer is", magic(5)) def magic(num): answer = num + 2 * 10 return answer main()

25

Consider the following code: def get_volume(width, height, length=2): volume = width * height * length return volume def main(): l = 3 w = 4 h = 5 v = get_volume(l, w, h) print(v) main() What value is passed to the height argument by the call to the get_volume() function?

4

What will this loop display? sum = 0 for i in range(0, 25, 5): sum += i print(sum)

50

Consider the following code: def get_volume(width, height, length=2): volume = width * height * length return volume def main(): l = 3 w = 4 h = 5 v = get_volume(l, w, h) print(v) main() When this program runs, what does it print to the console?

60

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

68

When applying the .3f formatting specifier to the number 76.15854, the result is __________

76.159

Which of the following is not an augmented assignment operator?

<=

Which language is referred to as a low-level language?

Assembly language

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

I'm ready to begin

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 result of the following code? ages = {'Aaron' : 6, 'Kelly' : 3, 'Abigail' : 1 } value = ages['Brianna']

KeyError

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

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

Which of the following does not apply to sets?

The elements are in pairs.

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

The path is D:\sample\test.

What does the acronym UML stand for?

Unified Modeling Language

What is the output of the following program? count = 5 while (count > 0): print("Woot!") count -= 1

Woot! is printed out 5 times

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 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]

The line continuation character is a

\

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

__str__

In Python, variable names may begin with ____________

a letter, an underscore

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, IDLE

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

a try/except statement

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

An if-elif-else statement can contain ____________ clauses.

any number of

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

argument

A statement of the form variableName = numericExpression is called a(n) ____________.

assignment statement

The ____________ statement causes an exit from anywhere in the body of a loop.

break statement

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

class Worker:

The ____________ statement causes the current iteration of the body of a loop to terminate and execution returns to the loop's header.

continue

Given a class named Customer, which of the following creates a Customer object and assigns it to the variable named cust1:

cust1 = Customer()

Consider the following code: class Rectangle: def __init__(self, height, width): self.height = height self.width = width def getPerimeter(self): perimeter = self.height * 2 + self.width * 2 return perimeter def getArea(self): area = self.height * self.width return area def getStr(self): return str(self.height) + " by " + str(self.width) Which of the following adds an attribute named color to the class?

def __init__(self, height, width): self.height = height self.width = width self.color = "red"

In a print statement, you can set the __________ argument to a space or empty string to stop the output from advancing to a new line.

end

A combination of numbers, arithmetic operators, and parentheses that can be evaluated is called a numeric ____________.

expression

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

false

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

false

Comments in Python begin with the // character

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

In the program development cycle, the first step in writing instructions to carry out a task is to determine how to process the input to obtain the desired output.

false

Python formats all floating-point numbers to two decimal places when outputting with the print statement.

false

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

false

Short -circuit evaluation is only performed with the not operator.

false

The else part of an if statement cannot be omitted.

false

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

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

The ____________ loop is used to iterate through a sequence of values.

for

A(n) __________ chart is also known as a structured chart.

hierarchy

The and operator has

higher precedence than the or operator, but lower precedence than the not operator

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?

if choice != 10:

In order to avoid KeyError exceptions, you can check whether a key is in the dictionary using the __________ operator.

in

Using a while loop to ensure a proper response is received from a request is called

input validation

In Python, variable names may consist of

letters,digits, and underscores

In programming terminology, numbers are called numeric ____________.

literals

A part of a program that executes a block of code repeatedly is called a(n) ____________.

loop

The procedures that an object performs are called

methods

Which of the following will get a floating-point number from the user?

my_number = float(input("Enter a number:"))

What will be displayed after the following code executes? guess = 19 if guess < 19: print("Too low") elif guess > 19: print("Too high")

nothing will display

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)

Assuming the random module has been imported, which of the following could possibly result in a value of 0.94?

number = random.random()

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

A for loop that uses a range() function is executed

once for each integer in the collection returned by the range() function

The parentheses of the range function can contain ____________ values.

one,two, and three

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

Given a variable named p that refers to a Product object, which of the following statements accesses the price attribute of the Product object?

p.price

Which of the following will display 20%?

print(format(0.2, '.0%')) <enter>

Which programming tool uses English-like phrases with some Python terms to outline the task?

pseudocode

Mutator methods are also known as

setters

Which type of error prevents the program from running?

syntax

When you code the dot operator after an object, what can you access?

the public attributes and methods of the 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

Both of the following for clauses would generate the same number of loop iterations.

true

Computer programs typically perform three steps: input is received, some process is performed on the input, and output is produced.

true

Decision structures are also known as selection structures.

true

In Python, print statements written on separate lines do not necessarily output on separate lines.

true

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

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

Python allows you to pass multiple arguments to a function.

true

The \t escape character causes the output to skip over to the next horizontal tab.

true

The if statement causes one or more statements to execute only when a Boolean expression is true.

true

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

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

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

What is the value of the variable phones after the following code executes? phones = {'John' : '5555555', 'Julie' : '5557777'} phones['John'] = '5556666'

{'John' : '5556666', 'Julie' : '5557777'}


Related study sets

WEEK 6 [ADN 225] CHAPTER 8"DISEASES & DISORDERS OF THE RESPIRATORY SYSTEM"

View Set

First and Second Industrial Revolutions

View Set

Deming's 14 Points for Management

View Set

Chapter 5 Plate Tectonics Section 2 Convection and the Mantle

View Set

Business Law II Mergers and Takeovers

View Set

Bio- unit 1-pt3- book notes- ch 13, 14, 15

View Set