Runestone Multiple Choice

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

Construct the code that will result in the value 134 being printed. #reference code

#reference code

Which of the following properly expresses the precedence of operators (using parentheses) in the following expression: 5*3 > 10 and 4+6==11

((5*3) > 10) and ((4+6) == 11)

Pick the best replacements for 1 and 2 in the following sentence: When comparing compilers and interpreters, a compiler is like 1 while an interpreter is like 2.

1 = translating an entire book, 2 = translating a line at a time

Consider the following Python code. Note that line numbers are included on the left. 1 2 3 4 5 6 7 8 9 10 11 def pow(b, p): y = b ** p return y def square(x): a = pow(x, 2) return a n = 5 result = square(n) print(result)

1, 5, 9, 10, 5, 6, 1, 2, 3, 6, 7, 10, 11

What is printed when the following statements execute? x = 12 x = x - 1 print(x)

11

What could the second parameter (12) in range(2, 12, 4) be replaced with and generate exactly the same sequence?

11, 13, or 14

What is the value of the following expression: 16 - 2 * 5 // 3 + 1

14

What is printed when the following statements execute? x = 12 x = x - 3 x = x + 5 x = x + 1 print(x)

15

Using the previous ActiveCode example, select the answer that is closest to the RGB values of the pixel at row 100, column 30? The values may be off by one or two due to differences in browsers.

183 179 170

What value is printed when the following statement executes? print(18 % 4)

2

Consider the following Python code. Note that line numbers are included on the left. 1 2 3 4 5 6 7 8 9 10 11 def pow(b, p): y = b ** p return y def square(x): a = pow(x, 2) return a n = 5 result = square(n) print(result)

25

In the following code, what is the value of number the second time Python executes the loop? for number in [5, 4, 3, 2, 1, 0]: print("I have", number, "cookies. I'm going to eat one.")

4

In the following code, how many lines does this code print? for number in [5, 4, 3, 2, 1, 0]: print("I have", number, "cookies. I'm going to eat one.")

6

What is printed by this code? n = 1 x = 2 while n < 5: n = n + 1 x = x + 1 n = n + 2 x = x + n print(n, x)

7 15

What is the value of the following expression: 2 ** 2 ** 3 * 3

768

What is printed when the following statements execute? n = input("Please enter your age: ") # user types in 18 print ( type(n) )

<class 'str'>

In Python a module is:

A file containing Python definitions and statements intended for use in other Python programs

What is a Boolean function? #see unit for "testing"

A function that returns True or False

What is a function in Python?

A named sequence of statements.

An algorithm is

A step by step list of instructions that if followed exactly will solve the problem under consideration.

What is the difference between a tab ('\t') and a sequence of spaces?

A tab will line up items in a second column, regardless of how many characters were in the first column, while spaces will not.

What is a local variable?

A temporary variable that is only used inside a function

What value is printed when the following statement executes? print(18 / 4)

A. 4.5

Which of the following is a run-time error?

A. Attempting to divide by 0.

Who or what typically finds semantic errors?

A. The programmer.

The difference between programming and debugging is:

A. programming is the process of writing and gradually debugging a program until it does what you want.

The activecode interpreter allows you to (select all that apply):

A. save programs and reload saved programs. B. type in Python source code. C. execute Python code right in the text itself within the web browser.

Debugging is:

A. tracking down programming errors and correcting them.

The print function:

B. . displays a value on the screen.

What value is printed when the following statement executes? print( int(53.785) )

B. 53

What are comments for?

B. For the people who are reading your code to know, in natural language, what the program is doing.

Which of the following is a syntax error?

B. Forgetting a colon at the end of a statement where one is required.

Who or what typically finds runtime errors?

B. The compiler / interpreter.

Who or what typically finds syntax errors?

B. The compiler / interpreter.

How can you determine the type of a variable?

B. Use the type function.

The differences between natural and formal languages include:

B. ambiguity, redundancy, and literalness.

Codelens allows you to (select all that apply):

B. control the step by step execution of a program. D. execute the Python code that is in codelens.

One reason that lotteries don't use computers to generate random numbers is:

Because computers don't really generate random numbers, they generate pseudo-random numbers.

What value is printed when the following statement executes? print(18 // 4)

C. 4

Which of the following is a semantic error?

C. Forgetting to divide by 100 when printing a percentage amount.

What is printed when the following statements execute? day = "Thursday" day = 32.5 day = 19 print(day)

D. 19

What is the data type of 'this is what kind of data'?

D. String

If you have a pixel whose RGB value is (50, 0, 0), what color will this pixel appear to be?

Dark red

Consider the following code: for aColor in ["yellow", "red", "green", "blue"]: alex.forward(50) alex.left(90)

Draw one side of a square.

Which direction does the Turtle face when it is created?

East

What does the following code print (choose from output a, b, c or nothing)? if 4 + 5 == 10: print("TRUE") else: print("FALSE")

FALSE

True / False: All standard Python modules will work in activecode.

False

True or False: Reading a program is like reading other kinds of text.

False

True or False: You can only have one active turtle at a time. If you create a second one, you will no longer be able to access or use the first.

False

True or False: the following is a legal variable name in Python: A_good_grade_is_A+

False

What does the following code print? if 4 + 5 == 10: print("TRUE") else: print("FALSE") print("TRUE")

False True

To find out information on the standard modules available with Python you should:

Go to the Python Documentation site.

Consider the following code: import turtle wn = turtle.Screen() alex = turtle.Turtle() alex.forward(150) alex.left(90) alex.forward(75)

It defines the module turtle which will allow you to create a Turtle object and draw with it

What is the difference between a high-level programming language and a low-level programming language?

It is high-level if the program must be processed before it can run, and low-level if the computer can execute it without additional processing.

What happens if you give range only one argument? For example: range(4)

It will generate a sequence starting at 0, with every number included up to but not including the argument it was passed.

What would the image produced from ActiveCode box 16 look like if you replaced the lines: newred = 255 - p.getRed() newgreen = 255 - p.getGreen() newblue = 255 - p.getBlue() with the lines: newred = p.getRed() newgreen = 0 newblue = 0

It would look like a red-washed version of the bell image

Will the following code cause an error? x = -10 if x < 0: print("The negative number ", x, " is not valid here.") else: if x > 0: print(x, " is a positive number") else: print(x," is 0")

NO This is a legal nested if-else statement. The inner if-else statement is contained completely within the body of the outer else-block.

Consider the code that prints the 3n+1 sequence in ActiveCode box 6. Will the while loop in this code always terminate for any positive integer value of n?

No one knows.

What will the following function return? def addEm(x, y, z): print(x + y + z)

None

How many statements can appear in each block (the if and the else) in a conditional statement?

One or more.

Which of the following best describes what is wrong with the previous example? #reference pic

Python is doing string concatenation, not integer addition.

In the command range(3, 10, 2), what does the second argument (10) specify?

Range should generate a sequence that stops before 10 (including 9).

In the random walk program in this section, what does the isInScreen function do?

Returns True if the turtle is still on the screen and False if the turtle is no longer on the screen.

True or False: You can rewrite any for-loop as a while-loop.

TRUE

Why do we type turtle.Turtle() to get a new Turtle object?

The first "turtle" (before the period) tells Python that we are referring to the turtle module, which is where the object "Turtle" is found.

What does the following code print? x = -10 if x < 0: print("The negative number ", x, " is not valid here.") print("This is always printed")

The negative number -10 is not valid here This is always printed

What is a variable's scope?

The range of statements in the code where a variable can be accessed.

Consider the following code: def square(x): runningtotal = 0 for counter in range(x): runningtotal = runningtotal + x return runningtotal

The square function will return x instead of x * x

How does python know what statements are contained in the loop body?

They are indented to the same degree from the loop header.

What is the most important skill for a computer scientist?

To be able to solve problems.

What is one main purpose of a function?

To help the programmer organize programs into chunks that match how they think about the solution to the problem.

True or False: A Turtle object can have any name that follows the naming rules from Chapter 2.

True

True or false: A function can be called several times by placing a function call in the body of a loop.

True

Which of the following is a Boolean expression? Select all that apply.

True 3 == 4 3 + 4 == 7

Is the following statement legal in a Python function (assuming x, y and z are defined to be numbers)? return x + y < z

YES It is perfectly valid to return the result of evaluating a Boolean expression.

Will the following code cause an error? x = -10 if x < 0: print("The negative number ", x, " is not valid here.") else: print(x, " is a positive number") else: print("This is always printed")

YES because the second else-block is not attached to a corresponding if-block.

Can you use the same name for a local variable as a global variable?

Yes, but it is considered bad form.

What is wrong with the following function definition: def addEm(x, y, z): return x + y + z print('the answer is', x + y + z)

You should not have any statements in a function after the return statement. Once the function gets to the return statement it will immediately stop executing the function.

hich type of loop can be used to perform the following iteration: You choose a positive integer at random and then print the numbers from 1 up to and including the selected integer

a for-loop or a while-loop

A program is:

a sequence of instructions that specifies how to perform a computation.

What will the following code print if x = 3, y = 5, and z = 2? if x < y and x < z: print("a") elif y < x and y < z: print("b") else: print("c")

c

Which of the following is a valid function header (first line of a function definition)?

def drawCircle(t):

What is the name of the following function? def drawSquare(t, sz): """Make turtle t draw a square of with side sz.""" for i in range(4): t.forward(sz) t.left(90)

drawSquare

Considering the function below, which of the following statements correctly invokes, or calls, this function (i.e., causes it to run)? Assume we already have a turtle named alex. def drawSquare(t, sz): """Make turtle t draw a square of with side sz.""" for i in range(4): t.forward(sz) t.left(90)

drawSquare(alex, 10)

Which of I, II, and III below gives the same result as the following nested if? #reference Pic

if x < 0: print("The negative number ", x, " is not valid here.") elif x > 0: print(x, " is a positive number") else: print(x, " is 0")

Which statement allows you to use the math module in your program?

import math

Which of the following is the correct way to reference the value pi within the math module. Assume you have already imported the math module.

math.pi

The following code contains an infinite loop. Which is the best explanation for why the loop does not terminate? n = 10 answer = 1 while n > 0: answer = answer + n n = n + 1 print(answer)

n starts at 10 and is incremented by 1 each time through the loop, so it will always be positive

The correct code to generate a random number between 1 and 100 (inclusive) is

prob = random.randrange(1, 101)

What command correctly generates the sequence 2, 5, 8?

range(2, 10, 3)

Which range function call will produce the sequence 20, 15, 10, 5?

range(20, 3, -5)

Click on all of the variables of type `int` in the code below

seconds = input("Please enter the number of seconds you wish to convert") hours = int(seconds) // 3600 total_secs = int(seconds) secs_still_remaining = total_secs % 3600 print(secs_still_remaining)

Click on all of the variables of type `str` in the code below

seconds = input("Please enter the number of seconds you wish to convert") hours = int(seconds) // 3600 total_secs = int(seconds) secs_still_remaining = total_secs % 3600 print(secs_still_remaining)

What are the parameters of the following function?

t, sz

Source code is another name for:

the instructions in a program, stored in a file.

Which module would you most likely use if you were writing a function to simulate rolling dice?

the random module

Which of the following explains why wait_time_int = int(wait_time_int) is an error?

wait_time_int does not have a value so it cannot be used on the right hand side.

What is a correct Python expression for checking to see if a number stored in a variable x is between 0 and 5?

x > 0 and x < 5

After the following statements, what are the values of x and y? x = 15 y = x x = 22

x is 22 and y is 15


Set pelajaran terkait

The Language of Medicine Chapter 1,2,3,4,5,7,8,9, 10, 11,12

View Set

finance chapter 11,12,13---wrong dont look at

View Set

Fund CH 4, PREPU health of individual, family, & community

View Set

Chapter 2: Chemistry Comes Alive

View Set

Who is being described? -Character/Quote ID- Block 2

View Set

Test 1 - Chromosome Abnormalities

View Set