BIS 228 Midterm

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

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

'r'

operators (explain)

+, -, *, /, etc. (python element)

augmented assignment operators

+=, -=, *=, /=, %=

What choices do you have to attend this course, taught in the HyFlex format?

- View the recorded stream online, after it has been posted online (asynchronous). - Attend in-person, up to the classroom capacity, as allowed by the class-splitting guideline. - Connect to the online stream during the class (synchronous).

python philosophy (explain)

-Beautiful is better than ugly. -Explicit is better than implicit. -Simple is better than complex. -Complex is better than complicated. -Readability counts. (there's preferably one obvious way to do something)

to create a python program, you can use...

-IDLE -a text editor -Jupyter Notebook

function (explain)

-a separate program that is called from a program (always followed by parentheses) -a group of statements that exists within a program for the purpose of performing a specific task

short-circuit evaluation

-and: if left operand is false, right operand is not evaluated (result is false) -or: if left operand is true, right operand is not evaluated (result is true)

string comparisons

-numbers are less than letters -capital letters are less than lower case letters -if all characters are the same, a longer word is greater than a shorter word

why use functions?

-simpler code -reusable code -better (and ultimately less) testing -faster development -enables teamwork

program development cycle

1) Design the program 2) Write the code 3) Correct syntax errors 4) Test the program 5) Correct logic errors

interpreter

1) Inspects each programming statement 2) Changes it to machine code 3) Executes it (and displays any results) 4) Waits for the next statement

compiler (explain)

1) Inspects the entire program (all statements) 2) Creates a machine code version of the program (only done for complete programs, unlike interpreter)

What is the output of the following code? val = 123456.789 print(f'{val:,.2f}')

123,456.79

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

2, 4, 6, 8

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

Programming assignments account for what percentage of the final grade of this course?

50%

Which of the following is not an augmented assignment operator?

<=

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

==

How does an interpreter differ from a compiler?

An interpreter inspects, executes, and delivers results statement by statement, while a compiler only inspects, executes and delivers results for complete programs.

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

Boolean

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? not (x < y or z > x) and y < z

False

nested loop example

Hours (0-23) Contain min (0-59) Contain sec (0-59)

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

I'm ready to begin

What is the late work policy for this course?

Late work may be accepted, with a penalty.

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) and (b == 1):

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

What is the best source for assignment due dates, quiz and exam dates, and topics for each class session?

The Course Schedule posted on Blackboard.

One of the design principles of Python is:

There should be one obvious way to do something

A flowchart is a tool used by programmers to design programs.

True

A while loop is called a pretest loop because the condition is tested before the loop has had the first iteration.

True

An action in a single alternative decision structure is performed only when the condition is true.

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

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

True

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

True

Python allows you to pass multiple arguments to a function.

True

Python function names follow the same rules as those for naming variables.

True

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

True

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

True

The instruction set for a microprocessor is unique and is typically understood only by the microprocessors of the same brand.

True

To assign a value to a global variable in a function, the global variable must be first declared in the function.

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

variable reassignment

When a variable is assigned a new value, the new value is stored in a new location, and the variable pointer is changed to the new value.

line continuation character

\

argument

a data item passed into a function when the function is called

f-string

a formatted string literal, which allows variables and formatting to be specified in output

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

a function

return

a function can return a value to the calling program by using the return statement

pass by value

a function cannot change the value of an argument in the calling program, but it can change the value of the parameter within the function

variable

a named location in memory which contains a value

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

a quote mark (")

string

a sequence of characters

pseudocode

a set of statements of what the program needs to do, written in natural language

parameter

a variable that receives an argument that is passed to the function

Boolean variable (explain)

a variable which has the value True or False (True and False are CAPITALIZED)

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

and

reusable code

any block of code that will be executed multiple times (especially from different points in a program) should be considered to become a separate function

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

argument

assignment statement

assigns what is on the right side of the = to the variable on the left

pass keyword

can be used to create a "blank" block, to be filled in later

range() function (explain)

can be used to return a sequence of iterable values (start value is the first value in a sequence and is 0 if not defined, the end value is NOT included, and then there's the increment)

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

string concatenation

combining several strings into a single string by using the plus (+) sign

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

global variables

created outside of any function definitions and are accessible to any of the functions

float

decimal number

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

==

equal to

exceptions (explain)

errors that occur at run time (use try/except structure to handle exceptions)

A single piece of data within a record is called a

field

opening a file in python

file_variable = open(filename, mode)

for loop syntax

for VARIABLE in LIST: statements

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

what programs do

gather input, process the input, provide an output

flowchart (explain)

graphically shows the flow of a program, using block symbols for each action (tool used by programmers to design programs)

Which of the following is the correct if clause to determine whether choice is anything other than 10?

if choice != 10:

if statement syntax

if condition: statement statement

if-elif-else statement syntax

if condition: statements elif: statements else: statements

if-else statement syntax

if condition: statements else: statements

None

indicates that the return has no value, or possibly to flag an error

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

The Python __________ is a program that can read Python programming statements and execute them.

interpreter

string literal (explain)

is a string containing the actual characters (delimited by quote marks)

In the string collating sequence used by Python, capital letters are _________ lower case letters.

less than

A __________ variable is created inside a function.

local

Which type of error allows the program to run, but give incorrect results?

logic

syntax errors

mistakes in writing the program statements, and prevent the program from running (error message generated)

logic errors

mistakes that cause the program to deliver incorrect results (or crash)

!=

not equal to

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

repetition structure (explain)

programming construct to allow repeated execution of a section of code (also called loop structures)

range() function example

range(2, 10, 2) would return 2, 4, 6, 8

r

read

while loop (explain)

repeats a statement or set of statements while a condition is true (this is a pretest loop, because the condition is tested before the statements are execute)

program design process

requires... 1) An understanding of what the program needs to do; and 2) Understanding of the steps that the program needs to perform (algorithm)

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

standard library

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

str

file extension

tells the operating system... -what type of data is stored in the file, and -what application should be used to open the file

syntax (explain)

the "rules" governing how a program is written (python element)

keyword arguments

the calling program may use the parameter names of the called program as keywords, to change the order of the arguments

Boolean expression (explain)

the condition tested by the if statement, and evaluates to either true or false (uses things like >, <, >=, etc.)

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

variable scope (explain)

the part of the program where a variable can be accessed (different functions can contain separate variables which have the same name)

keywords (explain)

things like "True", "False", "Elif", etc. (python element)

point of programming language

to make your programs readable and maintainable

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

logical decision statements

used to change the path of execution of a program, depending on true/false conditions

for loop

used to implement count-controlled repetition

Hungarian notation

uses a prefix (usually 1-3 characters) to indicate the type of the variable or control

A(n) __________ is a name that represents a value stored in the computer's memory.

variable

In the file name C:\Users\Documents\myfile.txt, what does the .txt extension tell the operating system?

what type of data is in the file, and what application should be used to open it

w

write


Kaugnay na mga set ng pag-aaral

CompTIA A+ (220-1001) 2.8 Networking Tools

View Set

Week 3 - Near Misses and Sentinel Events

View Set

Other Medications Administration

View Set

Chapter 1 - The Comparative Approach

View Set

English 11B - Unit 6: Final Exam

View Set

Meninges of the Brain, Frontal Section

View Set