Unit 4 & 5 Test

¡Supera tus tareas y exámenes ahora con Quizwiz!

What is the proper operator for "not equals" in Python?

!=

Why do we write functions?

- Make our code easier to understand by giving a readable name to a group of instructions - Avoid writing repeated code - Make our code reusable

Why do we use constant variables?

- To avoid having "magic numbers" (unique numbers with unexplained meaning) in our code - To give values a readable name, so that their purpose is clear - To let us easily change the behavior of our program by only having to change a value in one place

How many return values come out of the function sum? def sum(first, second): result = first + second return result

1

How many times will this program print "hello"?: i = 10 while i > 0: print("hello") i-= 1

10

What will be the value of sum after this code runs?: START = 1 END = 5 sum = 0; for i in range(START, END): sum += i

10

In the following code, what will be the last number to print to the screen before the program finishes?: for i in range(10): if i % 2 == 0: print(i) else: print(2 * i)

18

How many parameters go into the function sum?: def sum(first, second): result = first + second return result

2

How many possible values can the following code return random.choice([1,5]) return?

2

What is the output of the following code? def quadruple_number(x): quad_x = 4 * x print(quad_x) x = 5 quadruple_number(x)

20

How many times will the following code print "hello?": for i in range(0, 8, 2): print("hello")

4

What is printed by the following code?: def print_numbers(first, second, third): print(first) print(second) print(third) middle = 5 print_numbers(4, middle, 6)

4 5 6

How many times will the following code print "hello?": for i in range(3, 8): print("hello")

5

How many times will the following program print "hello"?: for i in range(5): print("hello")

5

What is the proper way to compare if two values are equal in a boolean expression in Python?

==

What symbol represents the and operator in AP Pseudocode?

AND

What symbol represents the or operator in AP Pseudocode?

OR

After the following code runs, what is the value of is_weekend? is_saturday = True is_sunday = False is_weekend = is_saturday or is_sunday

True

Which two of the following are valid values for a boolean?: True, Yes, False, No

True, False

We've written a function animate that moves a ball across the screen like this: def animate(event): ball.move(5, 5) How can we set up animate to be called every time a key on the keyboard is pressed down?

add_key_down_handler(animate)

What symbol represents the and operator in Python?

and

If I am using the following condition in my program: while True: Which keyword should I use to make sure I don't create an infinite loop?

break

Which Python keyword skips back to the beginning of a loop?

continue

Which of the following functions successfully returns the number 10?: def my_function(): 10 def my_function(10): return def my_function(): return 10 def my_function(): print 10

def my_function(): return 10

Which of the following functions successfully returns double the variable 'number'?: def my_function(number): return number*2 def my_function(number*2): return def my_function(): return number def my_function(number): number*2

def my_function(number): return number*2

If added to the program below, which of the following additional functions would not cause an error? x = 10 def add_nums(): y = 2 z = x + y print z def subtract_nums(): z = x - y print z def subtract_nums(): z = z - x print z def subtract_nums(): y = 5 z = x - y print z def subtract_nums(): z = y z = x - y print z

def subtract_nums(): y = 5 z = x - y print z

If we want to draw a circle using our helpful draw_circle function at position (300, 400) with a radius of 40 and color blue, which is the correct function call?

draw_circle(40, Color.blue, 300, 400)

What are the parameters of the print_numbers function?: def print_numbers(first, second, third): print(first) print(second) print(third)

first, second, third

In which namespace is the variable 'x' defined in the following program? x = 10 def add_nums(): y = 2 z = x + y print z

global namespace

Which of the following programs will not print anything?: x = True if x: print("hi") if False: print("hi") x = False if x: print("hi") else: print("hello") if False: print ("hi") else: print("Hello")

if False: print("hi")

Assume you are writing a program, and you have a boolean variable called b, defined like so: b = True Pick the correct if statement to follow the code above. The if statement should be correct Python, and the body of the if statement should only run if b is True. if b: print("b is True!") if True: print(b)

if b: print("b is True!")

How many times will this program print "hello"?: i = 50 while i < 100: print("hello")

infinitely

Do functions need to have parameters?

no

What symbol represents the or operator in Python?

or

How to return a random number between 1 and 10?

random.randint(1,10)

What is the parameter of the function quadruple_number? def quadruple_number(x): quad_x = 4 * x print(quad_x)

x


Conjuntos de estudio relacionados

practice exam missed questions question 4

View Set

DM- Chapter 11 Quiz Clinical Chemistry

View Set

Bio Unit 9 Evolution, Population Genetics, Phylogeny and Systematics

View Set

Planes Of Motion & Axes Of Rotation & Practice

View Set