BIS 228: Midterm 1

¡Supera tus tareas y exámenes ahora con 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'

String literals and variables may be concatenated by using which operator?

+

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 is the output of the following code? val = 123456.789print(f'{val:,.2f}')

123,456.79

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 if __name__ == '__main__': main()

25

Which of the following is not an augmented assignment operator?

<=

In Python the __________ symbol is used as the equality operator.

==

What is a group of statements that exists within a program for the purpose of performing a specific task?

A function

In Python, string comparisons are done using the _________ collating sequence.

ASCII

A function that return a logical value (True or False) is called a ________ function.

Boolean

A while loop is called a pretest loop because the condition is tested after the loop has had one iteration.

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

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

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 output of the following statement? print('I\'m ready to begin')

I'm ready to begin

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

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.

In the following statements, what will be the effect of short-circuit execution? Assume a = 2 and b = 1.if (a < 1) or (b == 1):

Only the (a < 1) logical expression will be evaluated

Functions that are built into Python are called ________ functions, and can be used by simply calling the required function.

Standard library

A flowchart is a tool used by programmers to design programs

True

A value-returning function is like a simple function except that when it finishes it returns a value back to the part of the program that called it.

True

Both of the following for clauses would generate the same number of loop iterations. for num in range(4):for num in range(1, 5):

True

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

True

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

True

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

True

Python allows you to pass multiple arguments to a function.

True

Since a named constant is just a variable, it can be changed any time during a program's execution

True

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

True

The function header marks the beginning of the function definition.

True

What file action ensures that all data is written to the file and ends the connection between the program and the file?

closing the file

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 = 4while count < 12: print("counting") count = count + 2

counting counting counting counting

Select all that apply. Which of the following are steps in the program development cycle?

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

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

escape

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

flowchart

Which of the following loop statements is equivalent to the following statement: for val in [2, 4, 6, 8, 10]:

for val in range(2, 12, 2):

Which of the following is the correct if clause to determine whether choice is anything other than 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:

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

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

A __________ variable is created inside a function.

local

Which logical operators perform short-circuit evaluation?

or, and

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

parameter

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

random

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

rstrip

In a print statement, you can set the __________ argument to a character string which will be placed between the printed output arguments.

sep

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


Conjuntos de estudio relacionados

Chapter 28 The Complete Physical Assessment: Infant, Child, and Adolescent

View Set

CH. 15 The use of ultrasound in the first trimester

View Set

ATI Reproductive and Genitourinary

View Set

Chap 53: Assessment and Management of Clients with Male Reproductive Disorders

View Set

Rational Number Review (perfects & decimals) & Approx. Square Roots

View Set