Jeopthy 1-10 study set

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

A Python string literal can span multiple lines if enclosed with

"""

What is the result of evaluating this expression: "{0}.{1:02}".format(13,8)?

"13.08"

Which of the following are valid string literals?

"Reese's script" "42" "my script" 'my script'

What character is used to indicate the beginning of a comment in Python?

#

The average of 2 numbers is the sum of the two numbers divided by 2. Enter a valid expression which computes the average of two variables a and b

(a+b)/2

Let's look again at the integer division (//) and remainder (%) operators. What if the dividend (top number) and/or divisor (bottom number) is negative? It turns out that the remainder is always computed to be the same sign as the divisor, and the integer division satisfies the rule a = (a//b) × b + a % b

-19 // 3 -7 -19 % 3 2 19 // -3 -7 19 % -3 -2 -19 // -3 6 -19 % -3 -1

Suppose the script snake2.py is in the current working directory, is executable, and has an appropriate 'shebang' line. What is the bash command for executing this script?

./snake2.py

What is the output from this code fragment? for i in range(3): for j in range(1,3): print(i*j, end=" ") print('#', end='')

0 0 #1 2 #2 4 #

Invoking range(stop) yields a sequence of integers, from 0 ... stop - 1. Suppose variable x has the value 3. What sequence is produced by the expression range(x + 2)? Enter your answer as a sequence of integers, separated by spaces.

0 1 2 3 4

The 3 steps the CPU performs when it processes a machine instruction are called:

1. fetch 2. decode 3. execute

The number of distinct patterns that can be represented with 7 bits is

128

Let's look at the integer division (//) and remainder (%) operators. Compute the value of the following expressions. Your answers should be integers for the first two answers. Your answers must be floating point for the second two answers (since the use of 3.0 rather than 3 forces the answer to be floating point).

13 // 3 4 13 % 3 1 11 // 3.0 3.0 11 % 3.0 2.0

How many times is the body of this loop executed? for index in range(14): print(index * 3)

14

Previously, we worked invoked the range function with only 1 parameter. However, the range function accepts up to 3 parameters, so providing additional flexibility as to the sequence of numbers we can obtain. What is the sequence of numbers generated by the invoking the following range? range(2, 7) Enter your answer as a series of integers, separated by commas. For example, if your answer were the first 3 counting numbers, you would enter 1,2,3

2,3,4,5,6

What is the sequence of numbers generated by the invoking the following range? range(28, 8, -4) As before, enter your answer as a series of integers, separated by commas.

28,24,20,16,12

What is the sequence of numbers generated by the invoking the following range? range(5, 17, 3) As before, enter your answer as a series of integers, separated by commas.

5,8,11,14

Evaluate the following expressions. Enter the result in the corresponding box (or the letter x if the evaluating the expression produces an error). If your answer is a float value, your answer should be accurate to at least 3 decimal places. In the corresponding dropdown box, indicate whether the result is an integer, float, or error condition.

5.0 / 14.0 + 6.5 * 2 13.357 float 10 % 3 + 9 // 4 3 integer 17 ** 3 + 3 / (2 * 8 - 16) x error

What are the smallest and largest possible values which the expression randrange(6, 17, 6) can produce?

6 12

Recall that the DieView class used Circle objects to represent pips. How many Circles were created in each DieView object?

7

What are the smallest and largest possible values which the expression randrange(9, 14) can produce?

9 13

A key requirement for implementing a sentinel loop is that

A key requirement for implementing a sentinel loop is that

Select the Python operator used for the following operations:

Addition + Subtraction - Multiplication * Floating point division / Integer division // Exponentiation ** Remainder %

Suppose day, month, and year are int variables containing the current day, month, and year numbers. Which of the following expressions would produce a properly formatted date in month/day/year format?

All of the above

A developer should use choose top-down, bottom-up, or spiral design, but not mix styles.

False

A docstring is the same thing as a comment.

False

A function may only be called at one place in a program.

False

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

False

A two-way decision is implemented using an if-elif-else construct.

False

An initial stripped-down version of a program is called a simulation.

False

An object may have only one instance variable.

False

Because Python identifiers are not case-sensitive, a Python variable named myvar can be referenced using any of the following: myvar, MYVAR, MyVar, myVar.

False

Evaluate this expression: True and False

False

Functions that live in objects are called instance variables.

False

If the following statement is executed, outfile = open('mydata.out', 'w') the program will crash if mydata.out already exists.

False

In Python conditions, "not equal" is written as /=.

False

In Python, some parameters are passed by reference.

False

In the Button class from the textbook, what does the clicked() method return if it is called on a deactivated button?

False

Instance variables go away once a method terminates.

False

Is the following expression always true, regardless of the values of a and b? not(a or b) == (not a) or (not b)

False

It's a bad idea to define new functions if it makes a program longer.

False

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

False

Post-test loops are useful control structures for input validation. Like other languages, Python directly implements these structures.

False

Programmers rarely define their own functions.

False

Programs no longer require modification after they are written and debugged.

False

Python keywords are good choices for Python identifiers (e.g., variable names or function names).

False

Python keywords comprise only lower-case letters.

False

The best way to become a better program designer is to read design books.

False

The best way to write a program is to immediately write down some code, then debug it until it works.

False

The first parameter of a Python method definition is called 'this'.

False

There is only one correct solution to a given problem involving decision structures.

False

a and (not a) a or (not a) a and ( a or (not a) )

False True Depends on the value of a

The term GUI stands for

Graphical User Interface

Select the corresponding character (or character sequences) that have the following mean in the bash command line interface.

Home directory ~ Current directory . Parent directory .. Path separator / Wildcard for filenames *

A function with no return statement returns

None

What class in the graphics.py module would be best for drawing a square?

Rectangle

What does the rgb stand for in the graphics function color_rgb?

Red Green Blue

What exception will the following code raise? a_list = list( range(15) ) for i in range(-1, 17): print('a_list[{}] = {}'.format(i, a_list[i]))

What exception will be raised? IndexError Why will this exception be raised? 15 is not a valid index for a_list

The first line executed in a Python script is a = b

What exception will be raised? NameError Why will this exception be raised? b is not defined

What exception will the following code raise? def ab(a,b) return a * b + b ab(5, '*')

What exception will be raised? SynataxError Why will this exception be raised? missing colon

What exception will the following code raise? def ab(a,b): return a * b + a ab(5, '*')

What exception will be raised? TypeError Why will this exception be raised? it's illegal to add a string to an integer

What exception will the following code raise? for i in range(10): rem = (((10)) % (i)) print('The remainder of 10 divided by {} is {}'.format(i, rem))

What exception will be raised? ZeroDivisionError Why will this exception be raised? 0 cannot be the second operand of %

What is the result of evaluating list(range(1,7,2))?

[1,3,5]

In a Python class definition, what is the special identifier used as the name of the constructor?

__init__

In a Python class definition, what is the special identifier used for a method which produces a string representation of the object?

__str__

The expression not (a==15 or b==15) is equivalent to

a != 15 and b != 15

A statement is

a complete computer command

The fragment for i in range(10): is an example of

a counted loop

The Python random() function produces

a pseudorandom float between 0 and 1

The expression randint(1,6) >= 5 evaluates to True

about 33% of the time

Evaluate the following expressions. Enter the result in the corresponding box (or the letter x if the evaluating the expression produces an error). If your answer is a float value, your answer should be accurate to at least 3 decimal places. In the corresponding dropdown box, indicate whether the result is an integer, float, or error condition.

abs(7 - 11 // 3) ** 3 64 integer math.sqrt(7 - 8) + 7 * 3 x error math.sqrt(abs(7 - 8)) + 7 * 3 22.0 float

A step-by-step set of instructions for accomplishing some task is called a(n)

algorithm

A prototype is

all of the above

Modern digital computers represent numbers

all of the above

The expression randrange(30) <= 30 evaluates to True

always

If a function returns a value, it is typically be called from

an expression

The fragment: i = 5 while i < 10: print(i * i)

an infinite loop

A Python convention for defining methods that are "private" to a class is to begin the method name with

an underscore (_)

The Python Boolean logic operators include

and, or, not

In the following Python function declaration def generate_message(name, message_type): what role do the the identifiers name and message_type play?

arguments parameters

If a function contains no return statement, it should be used

as a complete statement

Characterize the following line of Python script: x = x_0 + velocity * delta_t

assignment statement

The executable statements in a function are collectively called the

body

In a Button widget, what is the data type of the instance variable active?

bool

In the racquetball simulation, what data type is returned by the gameOver function?

bool

Alice just started work on an interactive maze game. She's not sure she knows how big to make the maze, so she starts her design by drawing a circle on the screen which will represent the player. She feels this approach will give her an idea of how large the maze should be. This design approach is an example of

bottom-up design

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

break

When a program instructs a function to execute, we say the function is

called invoked

What is the bash command for changing the working directory to its parent?

cd ..

What is the bash command for changing the working directory to /usr/bin ?

cd /usr/bin

What is the bash command for making file lab4.py executable by the user? Be sure you have used the correct filename before grading your answer.

chmod u+x lab4.py

What Python keyword starts a class definition?

class

To implement new objects, a programmer writes a(n)

class definition

Which of the following is not a step in pure top-down design?

construct a simplified prototype of the system

A method that creates a new instance of a class is called a(n)

constructor

What statement can be executed in the body of a while-loop to cause the condition to be re-tested immediately?

continue

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

control structure

usually begin a new Python script by copying an existing script that has some similarity to the script I want, then begin editing from there. Assume lab4.py exists in the current directory. What is the bash command for creating a copy of this script with the name lab5.py ? Be sure you have used the correct filenames before grading your answer.

cp lab4.py lab5.py

An object combines

data and operations

Create a function areaOfRectangle(rectangle), which calculates the area of a rectangle.

def areaOfRectangle(rectangle): p1, p2 = rectangle.getP1(), rectangle.getP2() deltaX = p2.getX() - p1.getX() deltaY = p2.getY() - p1.getY() return deltaX * deltaY

Create a function averageNaturals(n), which returns the average of the first n natural numbers (i.e., average of 1, 2, 3, ... , n). Assume that the argument n is an integer ≥ 1.

def averageNaturals(n): n = (1+n)/2 return n

reate a function buildSquare(center, side), where center is a Point object, and side is a float. Your function should return a Rectangle object that is a square centered at center, with side length side.

def buildSquare(center, side): half_side = side / 2 x, y = center.getX(), center.getY() p1 = Point(x - half_side, y - half_side) p2 = Point(x + half_side, y + half_side) return Rectangle(p1, p2)

In this category, you will be asked to define some simple functions, which require at most a few lines (often only 1 or 2 lines in the function body) to implement. Your code will have to follow very specific guidelines in order for the automatic grader to recognize it as correct. So that you will understand exactly what is expected, this first problem is a giveaway. I provide you with the code for the function ... all you have to do is cut-and-paste into the solution box. The area of a circle is given by the formula A=πr2 Write a function called circle_area which accepts a single parameter radius. Your function will return the area of a circle with the given radius. Simply cut-and-paste the following solution into the answer box: def circle_area(radius): return math.pi * radius ** 2 Behind the scenes, import math has already been executed, so you don't need to include any import statement to use the math library.

def circle_area(radius): return math.pi * radius ** 2

Write a function distance which accepts 4 parameters: x1, y1, x2, y2 (in that order). The function should return the distance between the points.

def distance(x1, y1, x2, y2): deltay = y2 - y1 deltax = x2 - x1 return math.hypot(deltax, deltay) # or, if you forgot about math.hypot # return math.sqrt(deltax ** 2 + deltay ** 2)

Write a Python function called herons(a,b,c) that accepts three parameters, the length of the 3 sides of a triangle, and returns the area of that triangle. Assume that the math library has already been imported, so you can use math.sqrt(x) to calculate a square root.

def herons(a,b,c): s=(a+b+c)/2 return math.sqrt(s*(s-a)*(s-b)*(s-c))

Write a function slope which accepts 4 parameters: x1, y1, x2, y2 (in that order). The function should return the slope of the line.

def slope(x1, y1, x2, y2): deltay = y2 - y1 deltax = x2 - x1 return deltay / deltax

The volume of a sphere is given by the formula V=43πr3 Write a function called sphere_volume which accepts has a single parameter radius. Your function will return the volume of a sphere with the given radius. As before, import math has already been executed, so you don't need to include any import statement to use the math library.

def sphere_volume(radius): return 4 / 3 * math.pi * radius ** 3

Create a function sumASCII(s), which returns the total (modulo 100) of the ASCII values of the characters in string s. Modulo is the mathematical term for remainder (e.g., 13 modulo 10 is 3).

def sumASCII(s): total = 0 for char in s: total += ord(char) return total % 100

Create a function sumAndSquareRoot(x), which returns a tuple. The argument x is a floating point number, and can be negative. The first element of the tuple (at index 0) is the square of x and the second element of the tuple is the square root of the absolute value of x.

def sumAndSquareRoot(x): return x * x,math.sqrt( abs(x) )

Create a function totalNCubes(n), which returns the total (sum) of the cubes of the first n natural numbers.

def totalNCubes(n): total = 0 for i in range(n): total += (i+1) ** 3 return total

Create a function totalOddSquares(n), which returns the total (sum) of the squares of all odd natural numbers ≤ n.

def totalOddSquares(n): total = 0 for i in range(1, n+1, 2): total += i * i return total

In the following Python code def greeting(person): pass

define

A string literal immediately following a class or function definition heading is a

documentation string (docstring)

A batch-oriented program is one that

does its input and output through files

What is the bash command for converting DOS-style line endings into Unix-style line endings?

dos2unix

Which of the following are Python keywords?

else pass

Keeping the details of how an object is represented inside a class definition is called

encapsulation

The Python numeric type for representing numbers containing fractional values is

float

Which of the following expressions result in a float value of 123?

float(int('123')) 123 / 1 float('123') 123.0

A method definition is similar to a(n)

function definition

Given the following function definition: def goodbye(): print("Goodbye World") What statement would you use to invoke this function?

goodbye()

Python is an example of a(n):

high-level programming language

Assume program execution has reached the first line of the code fragment below. Which lines will be executed? x = 7 // 2 if x > 3: x += 4 else: x *= 7

if x > 3: x *= 7 x = 7 // 2

Assume program execution has reached the first line of the code fragment below. Which lines will be executed? x = 4 if x > 3: x += 3 if x >= 7: x *= 7

if x >= 7: x *= 7 x = 4 if x > 3: x+= 3

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

if-elif-else

What Python statement allows the math library to be used in a program?

import math

In Python, the body of a decision is indicated by

indentation

Which of the following commands would be used to open a file called "foobar.dat" so that its contents could be read into memory?

infile = open("foobar.dat","r")

A loop that never terminates is called a(n) A priming read is part of the pattern for a(n) A loop structure that tests the loop condition after executing the loop body is called a(n) A loop pattern that continues until a special value is input is called a(n) A loop pattern that asks the user whether to continue on each iteration is called a(n)

infinite loop sentinel loop post-test loop sentinel loop interactive loop

The arrows in a module hierarchy chart depict

information flow

Which of the following is not a category of object methods?

instance variable

Data inside of objects is stored in

instance variables

The Python numeric type that is best for representing positive and negative whole numbers is

int

A(n) _____ analyzes and executes source code as necessary. An -----translates from source code written in high-level language to machine code.

interpreter compiler

Coordinate transformation

is a well-studied component of computer graphics

Consider the following fragment of code for processing the lines of a text file: line = infile.readline() while line != "": # process line line = infile.readline()

it reaches the end of the file

Which of the following is not true of top-down design

it's not suited for object-oriented programming

What is the bash command for listing all files (including directories) in the current working directory?

ls

Which of the following are listed as Trigonometric Functions in the Math library documentation?

math.cos(x) math.atan2(x)

Identifiers in Python may not contain

spaces

Which of the following are legal identifiers?

spam_and_eggs spam _3 spam4U spAm

A graphical view of the dependencies among components of a design is called a(n)

structure chart

Unit testing is

testing a component of a program in isolation

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

the bottom

Which of the following are steps in the function calling process?

the calling program suspends the body of the function executes the formal parameters are assigned the value of the actual parameters control returns to the point just after the function was called

One disadvantage of using binary floating point representations is that

they are often only approximations

The goal of the specification phase of the software development process is

to determine what the program should do

Which of the following are reasons to use functions?

to make a program more modular to reduce code duplication to make a program more self-documenting

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

Which of the following are Python keywords ?

try from continue

In lecture, the famous quotation "Damn the torpedoes, full-speed ahead!" was used to describe which control structure?

try-except

Python exceptions can be caught using what kind of statement?

try-except

Aliasing is the situation when

two different variables refer to the same object in memory

In modern Python, an int that grows very large

uses more memory

Main memory is ---- , which means that the information in memory is lost when power is turned off.

volatile

Although not covered in our textbook, augmented assignment is a relatively simple concept. See Lessons → Chapter 2 → Augmented Assignment. After the following code executes, what are the values for w, x, y and z? w, x, y, z = 3, 4, 5, 24 a, b, c, d = 13, 6, 3, 2 w += a x -= b y *= c z /= d

w: 16 x: -2 y: 15 z: 12.0

Which of the following are Python keywords?

while finally else not

In Python, indefinite loops are implemented using a

while-loop

How would you create a 200x200 graphics window titled MyWindow?

win = GraphWin('MyWindow')

What command would set the coordinates of win to go from (0,0) in the lower-left corner to (10,10) in the upper-right?

win.setCoords(0, 0, 10, 10)

Suppose you want to create a square graphics window and draw lines to divide it into four equal-sized quadrants. Fill in the missing line in this code: win=GraphWin('Four Square', size, size) # missing line here Line(Point(0,1),Point(2,1)).draw(win) Line(Point(1,0),Point(2,0)).draw(win)

win.setCoords(0,0,2,2)

The racquetball simulation showed that a player with a 5% advantage in skill

wins significantly more games than his opponent

Assume program execution has reached the first line of the code fragment below. Which lines will be executed? x = 3 if x > 3: x += 4 if x >= 3: x *= 7

x = 3 if x > 3:

Assume program execution has reached the first line of the code fragment below. Which lines will be executed? x = 3 if x > 3: x += 4 if x >= 7: x *= 7

x = 3 if x > 3: if x >= 7:

Suppose that the variable x currently has the value 20. What statement would cause the value of x to become 25?

x = x + 5

What is the condition in the following code fragment? x = 3 * 5 if x > 3: x += 3 x *= 6

x > 3

After executing the following code, what are the values of x, y, and z? x = 4 y = 5 z = 13 x, y, z = y, z, x

x: 5 y: 13 z: 4

The string "slots" that are filled in by the format method are marked by:

{ }

A sentinel loop should not actually process the sentinel value.

True

A simple decision can be implemented with an if statement.

True

A single try statement can catch multiple kinds of errors.

True

ASCII is a standard for representing characters using numeric codes.

True

An algorithm can be written without using a programming language.

True

An outer loop and an inner loop comprise nested loops.

True

Bottom-up design starts with low level details and works up to the big picture.

True

Certain methods which begin and end with two underscores have a special meaning in Python.

True

Encapsulation is only a programming convention in Python, and is not enforced per se.

True

Encapuslation allows us to modify and improve classes independently, without breaking other parts of the program.

True

Evaluate this expression: True or False

True

Every Python function returns some value.

True

Expressions are built from literals, variables, and operators.

True

Functions are useful for improving the logical design of programs by breaking them up into smaller, more readable chunks.

True

Hardware is the physical computer system; software contains the instructions used to control the hardware.

True

In Python "4" + "5" is "45".

True

In Python, a function can return multiple values by returning multiple expressions, separated by commas.

True

In mathematics, x=x+1 is nonsense, since subtracting x from both sides means 0=?1 However, in Python as in most computer languages, x = x + 1 is a legal statement.

True

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

True

Information can be passed into a function through parameters.

True

Instance variables are used to store data inside an object.

True

Is the following expression always true, regardless of the values of a and b? a and (b or c) == (a and b) or (a and c)

True

It is considered bad style to directly access an instance variable outside of a class definition.

True

Modules, variables, and functions are named using identifiers.

True

New objects are created by invoking a constructor.

True

Objects are instances of classes.

True

One reason to use functions is to reduce code duplication.

True

Python identifiers must start with a letter or underscore.

True

Strings are compared by lexicographic ordering.

True

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

True

The expression (a==b or True) evaluates to

True

The last character of a string s is at position len(s)-1.

True

The programming language Python is named after the British comedy troupe Monty Python's Flying Circus rather than the snake.

True

The readline() method for file objects returns all text up to and including the next newline character.

True

The split() method breaks a string into a list of substrings, and join() does the opposite.

True

Top-down design is also called stepwise refinement.

True

Traditionally, the upper-left corner of a graphics window has coordinates (0,0).

True

Using the / operator to divide two numbers always results in a float value, even if the two numbers are int's.

True

Variables defined in a function are local to that function.

True

Well-chosen function names and parameter names can make your code significantly more readable.

True

The literals for type bool are

True, False

A successor to ASCII that includes characters from nearly all written languages is

Unicode

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

ValueError

The statement infile = open('myfile.dat', 'r') has already been executed. Which of the following program fragments will display the contents of the file exactly as in the file?

print(infile.read(), end='')

Which of the following are functions in the Python math library?

radians(x) factorial(x) hypot(x, y) cos(x)

Which of the following are Python built-in functions ?

range() len() int() round() float()

An algorithm is like a

recipe

A function can send output back to the program with a(n)

return

Recall that the Student class had instance variables name, hours, and qpoints. What is the missing line from the following method definition? def gpa(self): # missing line

return self.qpoints / self.hours

What is the bash command for removing child directory lab3 from the current directory? Be sure you have used the correct directory name before grading your answer.

rmdir lab3

Suppose that variable x has the value 510.2975688242326. What is the result of the following invocations of round()?

round(x) 510.0 round(x,2) 510.3 round(x,-1) 510.0

What are the strings s and t after the following statements are exectuted? s = 'Flora' t = s.upper()

s: Flora t: FLORA

What are the strings s, c, and r after the following statements are executed? s = 'loopholes'.upper() c = 'o'.upper() r = s.replace(c, c.lower())

s: LOOPHOLES c: O r: LooPHoLES

Given a string s, which of the following is/are the same as s?

s[:5] + s[5:] s[0:] s[:len(s)] s[:]

Given a string s, that is at least 3 characters long, which of the following is the same as s[0:-1]?

s[:len(s)-1]

What condition is True when a racquetball game is still in progress (i.e., game not over) and False if it has ended?

scoreA < 15 and scoreB < 15

Magnetic or optical media are generally used for:

secondary memory

Within a method definition, the instance variable x could be accessed via which expression?

self.x

What is the missing line of code from this fragment taken from the racquetball simulation: if serving == "A" if random() < probA: scoreA += 1 else: # missing line

serving = "B"

Which of the following methods is not part of the Button class in this chapter?

setLabel

What command would be used to draw the graphics object shape into the graphics window win?

shape.draw(win)

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

short-circuit

In top-down design, problems are broken down into

smaller problems

Identify the type of assignment in the following lines of code:

Augmented Assignment c *= z Simultaneous Assignment c, y = 9 , 17 Simple Assignment c = z * z

An expression that evaluates to either True or False is called

Boolean

Which statement correctly draws a circle of radius 10 centered at (50,50) in the graphics window win?

Circle(Point(50,50), 10).draw(win)

Which of the following classes are in the graphics library?

Line Polygon Rectangle Oval

What expression would create a line from (2,3) to (4,5)?

Line(Point(2,3), Point(4,5))

Assume program execution has reached the first line of the code fragment below. Which will be printed? x, y = 3, 3 try: z = 4 / (x - y) print("There's no place like home") except ZeroDivisionError: print('Lions and tigers and bears!') except ValueError: print('Oh my!') except NameError: print("I don't think we're in Kansas anymore!") except OverflowError: print("Run, Toto, run!")

Lions and tigers and bears!

A simulation that uses probabilistic events is called

Monte Carlo

A decision structure is one type of control structure.

True

A loop which exits from within the body of the loop is sometimes known as a 'loop and a half'.

True

Given a float value, we frequently want an int value near the float value. Depending on the situation, we may want the next higher or next lower integer, or we may want the closest integer. Note the use of the floor ⌊⌋ and ceiling ⌈⌉ symbols, which you may not have seen before. floor(x) = ⌊x⌋ is the largest integer ≤ x ceiling(x) = ⌈x⌉ is the smallest integer ≥ x. Ref: Wikipedia: Floor and ceiling functions We can also round off to the nearest integer, or truncate toward zero. Suppose x is 1.628. Use the Python interpreter (remembering to import the math library) for the following computations, which should help you understand how these functions work.

math.floor(x) 1 math.floor(-x) -2 math.ceil(x) 2 math.ceil(-x) -1 math.round(x) 2 math.round(-x) -2 math.trunc(x) 1 math.trunc(-x) -1

Which of the following are listed as constants in the Math library?

math.pi math.e

Suppose p1 and p2 are Point objects. What expression(s) could compute the distance between these two points?

math.sqrt((p2.getX()-p1.getX())**2 + (p2.getY()-p1.getY())**2) math.hypot( p2.getX()-p1.getX(), p2.getY()-p1.getY() )

The operations that an object knows are called

methods

What is the bash command for creating a directory in the file system?

mkdir

Here is the pattern for an interactive loop. What is the missing condition? set moredata to "yes" while « missing condition here » get the next data item process the item ask user if there is moredata

moredata is "yes"

A function can modify the value of an actual parameter only if it's

mutable

Given a Text object named myText, which statements would be combined to produce bold arial font, size 16 points?

myText.setFace('arial') myText.setStyle('bold') myText.setSize(16)

Given a Text object named myText, which statements would be combined to produce bold arial font, size 16 points?

myText.setFace('arial') myText.setStyle('bold') myText.setStyle('bold')

Placing a decision inside of another decision is an example of

nesting

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

not(a and b) == not(a) and not(b)

Which of the following expressions correctly determines if two points (p1 and p2) are at the same location?

p1.getX()==p2.getX() and p1.getY()==p2.getY()

A graphics display is composed of a grid of very small picture elements whose color can be controlled. These elements are called

pixels

Formal and actual parameters are typically matched up by

position


Set pelajaran terkait

Nutrition in Health : Chapter 1: Introduction to Nutrition

View Set

PATHO FINAL 1st set 162 question

View Set

ATV 5A Vocabulario - Sustantivos, Verbos, Adjectivos, Adverbios y Expresiones

View Set

Chapter 21 - Social Movements and Social Change

View Set

chapter 8 food for thought: The globalization of Agriculture

View Set

management exam 1 practice questions

View Set

Module 11 Review Quiz: Linux installation and configuration

View Set