Python Exam 3

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

Which of the following statements is true about computer simulation -They model real world exactly -Once the sim is written, the input values can be tweaked to see how it affects the results -All computer sims are easy to write -All of the above -None of the above

-Once the sim is written, the input values can be tweaked to see how it affects the results

What are the advantages of spiral development -It makes it easier to tackle a large rpoblem when you don't know ahead of time all the features your program must implement -It allows you to add new features and test them even if they weren't part of the initial requirements of the program -It allows you to simplify the original problem that may be too complicated to understand initially -All of the above -None of the above

All of the above

Which of the following can be treated as boolean expression -an int expression -a float expresion -the result of a comparison operator(such as < or >) -all of the above

All of the above

An expression that evaluates to either true or false is called

Boolean

Which of the following is not a step in pure top-down design -repeat the process on smaller problems -Detail the algorithm in terms of its interfaces with smaller problems -Construct a simplified prototype of the system -Express the algorithm in terms of smaller problems

Construct a simplified prototype of the system

T or F reading design books alone wil make you a great developer

False you need lots of practice

T or F a simplified version of a program is called a simulation

False, prototype

T or F a developer should use either top-down or spiral design, not both

False, they are complimentary

T or F not(a or b) == (not a) or not(b)

False. (DeMorgan's Law, p. 251)

T or F A Python while implements a definite loop.

False. A "for" implements a definite loop; a while implements an indefinite loop. (p. 235)

T or F A two-way decision is implemented using an if-elif statement.

False. A two-way decision is implemented using an if-else statement. (p. 210)

T or F A sentinel loop asks the user whether to continue on each iteration.

False. An interactive loop asks the user to continue. (p. 237-238)

T or F a top-down design is best implemented from the top down

False. Bottom-up implementation is ofted used

T or F The Python random function returns a psuedo-random int

False. Floating point between 0 and 1

T or F The easiest way to iterate through the lines of a file in Python is to use a while loop.

False. In Python, the easiest way is with a for loop: for line in infile: In many languages, though, the while loop is the better choice for this type of processing. (p. 242-244)

T or F Input validation means prompting a user when input is required.

False. Input validation refers to the process of verifying that a users input will work in the program. Some input validation can take place with a try-except statement. (p. 216-218, 252)

A method definition is similar to a ____

Function definition

Which of the following is not a valid rule of Boolean algebra?

It should be: not(a and b) == not(a) or not(b) is wrong

Which of the following statements is true about the Python expression x == 3 or 4 -It is an invalid statement and the Python interpreter will indicate its a syntax error -It will be true if x is 3 of if x is 4, and false for any other values -It will always be false -It will always be true

It will always be true

A while loop written as while True

Might be an infinite loop depending on what the loop body contains

A simulation that uses probabilistic events is called

Monte Carlo

A simulation that uses probabilitic events is called

Monte Carlo

T or F A python while implements an indefinite loop

True

T or F A sentinel loop should not actually process the sentinel value.

True

T or F A simple decision can be implemented with an if statement.

True

T or F A single try statement can catch multiple kinds of errors.

True

T or F In a Python class, the constructor is called __init__

True

T or F New objects are created by invoking a constructor

True

T or F The Boolean operator or return True when both of its operands are true.

True

T or F The math.sqrt function cannot computer the square root or a negative number.

True willl throw error (??)

The literals for type bool are

True, False

T or F The condition x <= y <= z is allowed in Python.

True, although this is an unusual Boolean construction that would not be permitted in most programming languages. (p. 220)

T or F a and (b or c) == (a and b) or (a and c)

True. (p. 250 has Boolean algebra rules)

When a program is being run directly (not imported), the value of __name__ is

__main__

Which of the following statements could be true about the following python code? from random import randrange for i in range (10): print(randrange(10)) -It might output the numbers 0-9 in that order -It might output 0-9 in some order -It might output 0 ten times -all of the above -none of the above

all of the above

Int eh racquetball simulation, what data type is returned by the gameOver function

bool

What statement can be executed in the body of a loop to cause it to terminate?

break

What python reserved word starts a class definition

class

A statement that controls the execution of other statements is called a

control structure

In Python, the body of a decision is indicated by

indentation

A loop that never terminates is called

infinite

The arrows in a module hiearchy charrt depict

information flow

A loop pattern that asks the user whether to continue on each iteration is called

interactive loop

A loop pattern that asks the user whether to continue on each iteration is called a(n)

interactive loop

A multiple choice question is most similar to _______

multi-way decision

A multiple choice question is most similar to

multi-way decisions

Placing a decision inside of another decision is an example of

nesting

Planning a decision inside of another decision is an example of:

nesting

The initial version of a system used in spiral development is called a

prototype

What expression is true approximately 66% of the time

random() < 0.66 (???????)

A loop pattern that continues until a special value is input is called ______

sentinel loop

A loop pattern that continues until a special value is input is called a(n)

sentinel loop

The term for an operator that may not evaluate one of its subexpressions is

short-circuit

The easiest place in a system structure to start unit-testing is

the bottom

What is the purpose of an if statement

to choose whether or not to execute certain code

What is the purpose of exception handling

to handle errors gracefully so the program does not crash

A structure in which one decision leads to another set of decisions, which leads to another set of decisions, etc., is called a decision

tree

T or F Top-down design is also called stepwise refinement

true

How is a percent sign indicated in a string-formatting template

%

Which line would not be found in a truth table for and?

(c) T F T

A priming read is part of the pattern for a(n)

(c) sentinel loop (p. 240)

A loop structure that tests the loop condition after executing the loop body is called a

(d) post-test loop (although choice (b)--loop-and-a-half--is a strategy used to execute post-test loops in Python)

Which of the following statements is true: -an if statement must have an else statement -an if statement must have an elif statement -An if statement must have both an elif and an else statement -An else statement must have a matching if if statement

-An else statement must have a matching if if statement

Which of the following statements is true? -There is usually one algorithm to solve a problem -There is often more than one way to solve a problem and some ways may be more efficient than others -There is often more than one way to solve a problem but they are all equally efficient -all of the above -none of the above

-There is often more than one way to solve a problem and some ways may be more efficient than others

Which of the following is not a step in pure top-down design -Repeat process on smaller problems -detail algorithm in terms of its interfaces with smaller problems -construct a simplified prototype of the system -Express the algorithm in terms of smaller problems

-construct a simplified prototype of the system

What would be the final value of total for the following program? total = 0 for i in range(10): for j in range(10): total = total + 1

100

Which line would not be found in a truth table for or?

F T F

T or F Computers can generate truly random numbers

False

T or F The counted loop pattern uses an indefinite loop

False

T or F Multi-way decisions must be handled by nesting multiple if-else statements.

False. Multiple if-else statements are one way to manage a multi-way decision, but if-elif-else statements may be used as well. (p. 213)

T or F A while loop is a post-test loop.

False. The while loop tests the condition before the body of the loop. Python doesn't have a post-test loop construction, although some languages do. (Pascal, for example, has a repeat-until statement.) (p. 217-218)

T or F There is usually only one correct solution to a problem involving decision structures.

False. This chapter is filled with examples showing alternative approaches to making decisions. (Also, see p. 226)

T or F In Python conditions, ≠ is written as /=.

False. ≠ is written as !=. (p. 205)

T or F The counted loop pattern uses a definite loop.

True

T or F Top-down design is also called stepwise refinement

True

T or F True or False

True

T or F a while is a pre-test loop

True

T or F functions that live in objects are called methods

True

T or F in top-down design the main algorithm is written in terms of functions that don't exist yet

True

T or F in top-down design, the main algorithm is written in terms of functions that don't exist yet

True

T or F the main function is at the top of a functional structure chart

True

T or F unit testing is the process of trying out a component of a larger program in isolation

True

T or F Strings are compared by lexicographic ordering.

True. ("Lexicographic ordering" is alphabetical according to Unicode values.)

Taking the square root of a negative value with math.sqrt produces a(n)

ValueError

T or F Computers can generate truly random numbers

false

in top-down design, the subcomponents of the design are

functions

Which of the following Python statements is invalid: -if x!=4: -if x = 4: -if x == 4: -if 2< x < 4:

if x = 4:

The best structure for implementing a multi-way decision in Python is

if-elif-else

the term for an operator that may not evaluate one of its sub-expressions is called

short-circuit

A graphical view of the dependncies among components of a design is called a

structure chart

What is unit testing

testing separate parts/units of the program separately

A structure in which one decision leads to another set of decisions, which leads to another set of decisions, etc., is called a decision _____

tree


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

Research Methods Exam 2 Study Guide

View Set

Hist. 111: Foner Ch. 23 Practice Questions

View Set

Principles of Accounting Chapter 20: Process Cost Systems

View Set

Cell Structure and Function Practice Test Questions

View Set