ap csp testsssss

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

If name is 'John', what is the result when we run 'Hello ' + name + 'How are you?'?

'Hello JohnHow are you?'

What is the value of s[3], if we define s = 'H1 th3re!'

't'

Which of the following compound conditions will be true when x = 100 and y = 50?

((x > 50) and (y < 100))

Suppose we have a circle with radius 25, stored in the variable ball. Which of the following expressions evaluates to true only when the circle is entirely contained within one of the red zones? [1 point]

(ball.centerX < 200) OR (ball.centerX > 375)

Which ONE of the following is not logically the same as (x >= 5)?

(x > 5) and (x == 5)

What is the centerX of c after we press the mouse once, according to the code below? g = Group(Star(200, 200, 10, 10)) c = Circle(100, 100, 5, fill='red') g.add(c) def onMousePress(mouseX, mouseY): g.centerX += 10 c.centerX += 5

. 115

Which shape is not black at the top?

. Rect(50, 50, 100, 100, fill=gradient('black', 'yellow'))

Which of the following is the correct way to create a function in Python?

. def my_function():

If we had a CMU Graphics library for use outside of the site, which lines are used to draw a Rect? I. import cmu_graphics II. cmu.graphics.Rect(150,150, 100, 100, fill='blue') III. Rect(150,150, 100, 100, fill='blue')

.I and II

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

1

What are the possible values that random.randint(1, 5) can return?

1, 2, 3, 4, 5

What is the centerX of c after we press the mouse once, according to the code below? g = Group(Star(200, 200, 10, 10)) c = Circle(100, 100, 5, fill='red') def onMousePress(mouseX, mouseY):g.centerX += 10 c.centerX += 5

105

What is the centerX of c after we run the code below? g = Group(Star(200, 200, 10, 10)) c = Circle(100, 100, 5, fill='red') for shape in g.children: c.centerX += 5

105

What is the output of the following program?def sum_to(num): sum = 0 for i in range(num+1): sum += i print(sum)x = 5sum_to(x)print(x)

15 5

How many times will f(b) be called if a = 1 and b = 8? if(b > 8): if (a == 1): f(b) else: if (b == 8): f(b) if (a > 0): f(b)

2

Which of the following is NOT a type?

42

If we call checkWeather, what is the maximum number of functions that can be called (including checkWeather)? def checkWeather(isSunny, Temperature): if (isSunny == True): wearHat() if (Temperature < 32): wearHeavyJacket() elif (Temperature == 70): perfectDay() else: stayInside() else: bringUmbrella() if (Temperature < 32): wearHeavyJacket() elif (Temperature < 70): wearJacket() wearJeans()

5

Which of the following are ALL the possible values that a call to random.randint(2, 5) might return?

5, 3, 4, 2

How many shapes are drawn based on the code below? def drawShapes(centerX, centerY, radius, points, color): Star(centerX, centerY, radius, points, fill=color) RegularPolygon(centerX, centerY, radius, points, fill=color) Rect(200, 200, 100, 100, fill=color) drawShapes(300, 200, 20, 6, 'navy') drawShapes(100, 200, 50, 8, 'mediumVioletRed')

6

The following code segment is intended to do the following: When the mouse is pressed, a circle is created with a fill matching the color at the current index in app.colorList. The code segment does not work as intended. app.index = 0 app.colorList = [ 'red', 'orange', 'yellow', 'green', 'blue', 'indigo', 'violet' ] PROCEDURE onMousePress(x, y) { app.index ← app.index + 1 Circle(x, y, 25, fill=app.colorList[app.index]) } How many times do we need to press the mouse to get an error?

8

For what values of z will the following compound condition be false? if ((not (z == 4)) and (z <= 7)): f(z)

8, 4

What will be count.value after the code is run and the mouse is clicked once? shapes = Group( Circle(200, 200, 20), Circle(10, 10, 20), Star(300, 300, 10, 5) ) count = Label(0, 200, 200, size=24) for i in range(5): count.value += 3 def onMousePress(mouseX, mouseY): for shape in shapes.children: count.value -= 2

9

When is a compound conditional that uses the keyword 'and' True?

Both tests are true

How can we include the random functions in our code?

By including the line "import random".

What will be drawn when we call f(x)? def g(): Label('Hi! ', 120, 200, size=24) def f(x): g() Label("I'm happy", 200, 200, size=24)

Hi!I'm happy

Which of the following compound conditions are equivalent to the following nested conditionals? if (x > 200): if (y < 200): I. ((x > 200) and (y < 200)) II. (x > 200 and y > 200) III. not ((x <= 200) or (y >= 200))

I and III

Which event-handling function should you use if you want to move a shape?

It depends

Which of the following is true about the onStep function?

It is called automatically by the app at a set interval.

Which of the following lines of code has an error?

Line(10, 10, 100, lineWidth=101)

Which of the following shapes has an error?

Polygon(100, 200, 150)

What type of value is 12.25?

float

Which of the following would be a legal function call for the given code below? def greet(labelSize, color): Label('Hi', 100, 100, fill=color, size=labelSize) a greet('white', 40) b greet(20, 'blue') c greet('yellow', 'pink') d greet(20, 60)

greet(20, 'blue')

Consider the following procedures: PROCEDURE g(a) { IF(a MOD 2 ≠ 0) { RETURN(a + 1) } ELIF((a > 10) and (a MOD 3 == 0)) { RETURN(a / 10) } } PROCEDURE h(b) { IF(b < 5) { IF(g(b) > 3) { RETURN(b - 1) } ELIF(b > 3) { b ← b + 1 } } ELSE { RETURN(g(b)) } Which of the following procedure calls results in a value besides None being returned?

h(3)

Do functions need to have parameters?

no

Which of the following is not a valid property of Circles?

none of these

Which of the following functions successfully returns double the variable 'number'?

def my_function(number): return number*2

The following algorithm is intended to take a list of shapes and returns a new list that has no overlapping, blue shapes in it. Line 1: PROCEDURE removeOverlapping(shapeList) Line 2: { Line 3: newList = [] Line 4: index ← 1 Line 5: REPEAT LEN(shapeList) TIMES Line 6: { Line 7: shape ← shapeList.remove(RANDOM(0, LEN(shapeList))) Line 8: IF(shape.fill ≠ 'blue') Line 9: { Line 10: doesShapeOverlap ← checkOverlap(shape, newList) Line 11: IF(doesShapeOverlap = false) Line 12: { Line 13: newList.append(shape) Line 14: } Line 15: } Line 16: index ← index + 1 Line 17: } Line 18: } This procedure does not work as intended. How could we fix it? You may assume the checkOverlap procedure accurately returns true if the shape overlaps with any shape in the provided list and false otherwise.

Replace Lines 8-11 withdoesShapeOverlap ← checkOverlap(shape, newList)IF((doesShapeOverlap = false) OR (shape.fill ≠ blue))

What will app.index be if we run the following code and click the mouse 10 times? app.index = 0 app.list = [ 1, 2, 3 ] def onMousePress(x, y): app.index = (app.index + 1) % len(app.list)

a. 1

g = Group(Star(200, 200, 10, 10)) c = Circle(100, 100, 5, fill='red') for shape in g.children: shape.centerX += 5

a. 100

Consider the following code snippet:WIDTH = 300HEIGHT = 300def draw_circle(radius, color, x, y): circle = Circle(radius) circle.set_color(color) circle.set_position(x, y) add(circle)draw_circle(40, "red" 100, 300)draw_circle(50, "green", 50, 100)draw_circle(70, "blue", WIDTH/2, HEIGHT/2)draw_circle(25, "yellow", WIDTH/2, 300)In the third call to draw_circle(), what values are passed to the coordinates of the center of the circle?

a. 150, 150

What gets printed after the code below is run? languages = [ 'python', 'spanish', 'english' ] language = languages.remove('english') print(language)

a. None

Which of the following has an error?

a. Rect(30, 30, 100, 200, fill=none)

Which of the following functions successfully returns the number 10?

a. def my_function():return 10

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?As a reminder, here's the function header for draw_circle:def draw_circle(radius, color, x, y)

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

Which of the following is true about if-elif-else statements?

a. After using if, an elif can be added as an additional test.

In the following function print_three_times:def print_three_times(word): print(word) print(word) print(word)What is the parameter of the function?

a. word

What is the value of s in the code below? myList = [ 1, 2, 3 ] s = myList[0] + myList[2]

b. 4

Why do we write functions? a. Make our code reusable Selected:b. All of these This answer is correct. c. Make our code easier to understand by giving a readable name to a group of instructions d. Avoid writing repeated code

b. All of these

When is a compound conditional that uses the keyword 'or' True?

b. At least one test is true

Which shape is invisible on the canvas?

b. Rect(50, 50, 100, 100, fill=None)

Since we can often solve the same problem using multiple conditionals, or compound conditionals, or nested conditionals, how do we know which of these to use for a given problem?

b. Use whatever seems clearest to you for that particular problem.

Which of the following are the parameter(s) of the function greet shown below? def greet(labelSize, color): Label('Hi', 100, 100, fill=color, size=labelSize)

b. color and labelSize

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

b. def subtract_nums():y = 5z = x - yprint z

Question 8 The following code defines the drawShapes() procedure that draws shapes depending on what the arguments are: PROCEDURE drawShapes(lotsOfShapes, x) { IF(lotsOfShapes = true) { Circle(200, 200, 50, fill='blue') Rectangle(x, 200, 100, 100, fill='green') } ELSE { Circle(200, 200, 50, fill='red') } IF(x ≥ 150) { Rectangle(200, 200, 100, 100, fill='green') } } What should the procedure call look like in order to draw both a red circle and a green rectangle (and nothing else)?

drawShapes(false, 150)

Suppose we have a shape player with the custom property player.hunger and a custom method player.die(). We want the player to die if their hunger reaches 0. Which of the following code segments properly write this code? I. PROCEDURE onMousePress(mouseX, mouseY) { player.hunger ← player.hunger - 1 IF(player.hunger = 0) { player.die() } } II. PROCEDURE onMousePress(mouseX, mouseY) { IF(player.hunger ≠ 0) { player.hunger ← player.hunger - 1 } ELSE { player.die() } } III. PROCEDURE onMousePress(mouseX, mouseY) { player.hunger ← player.hunger - 1 IF(player.hunger > 0) { player.die() } }

b. I and II

What is the centerX of c after we press the mouse once, according to the code below? g = Group(Star(200, 200, 10, 10)) c = Circle(100, 100, 5, fill='red') def onMousePress(mouseX, mouseY):g.centerX += 10 c.centerX += 5

c. 105

What is the centerX of c after we run the code below? g = Group(Star(200, 200, 10, 10)) c = Circle(100, 100, 5, fill='red') for shape in g.children: c.centerX += 5

c. 105

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

c. 4 5 6

How many times will the print statement be called in the code below? for i in range(3): for j in range(3): print(i, j)

c. 9

How does a label change if you set 'bold=True'?

c. It makes the text thicker.

What is the purpose of a return statement in a function?

c. Stops executing the function and returns the value

What is the value of languages after the code below is run? languages = [ 'python', 'spanish', 'english' ] languages.append('french')

c. [ 'python', 'spanish', 'english', 'french' ]

Which of the following correctly multiplies the centerX of a circle called c by 4?

c. c.centerX *= 4

Which of the following is the correct way to bring a circle named c to the front of the canvas? a. front(c) b. toFront(c) Selected:c. c.toFront() This answer is correct. d. c.toFront

c. c.toFront()

Consider the drawKabob procedure: PROCEDURE drawKabob(flavors) { Line(30, y, 400, y, fill='cornSilk', lineWidth=20) index ← 1 REPEAT LEN(flavors) TIMES { centerX ← 75 + index * 50 IF(flavors[index] = 'meat') { Circle(centerX, 200, 25, fill='sienna') } IF(flavors[index] = 'veggie') { Line(centerX, 175, centerX, 225, fill='green', lineWidth=35) Line(centerX, 175, centerX, 225, fill='red', lineWidth=20) Line(centerX, 175, centerX, 225, fill='white', lineWidth=5) } index ← index + 1 } } Which answer provides the proper procedure arguments to draw the image below? [1 point]

c. drawKabob([ 'veggie', 'meat', 'meat', 'veggie', 25, 'veggie' ])

Consider the code snippet:def draw_circle(radius, color, x, y): circle = Circle(radius) circle.set_color(color) circle.set_position(x, y) add(circle)What is the return value for this function?

c. this function has no return value

Which of the functions is called when ticketsBought = 12? if (ticketsBought < 12): cancelShow() elif (ticketsBought == 12): reachedGoal() else: soldOutShow('yellow')

c. reachedGoal

Which of the functions is called? def checkWeather(isSunny, isCold): if (isSunny == True): wearHat() elif (isCold == True): wearJacket() else: bringUmbrella() checkWeather(True, False)

checkWeather and wearHat

Which is equivalent to random.choice(colorList)?

colorList[random.randint(0, len(colorList) - 1)]

What is the value of favoriteAnimal after the code below is run? animals = [ 'dog', 'cat', 'cow', 'pig' ] favoriteAnimal = animals[2]

cow

Your teacher wants to write a program to add 5 points to everyone's grades, which are stored in the list app.grades. But your teacher doesn't know how to code so they've enlisted your help in exchange for giving you an extra 2 points (7 total)! You know your grade is the last one in the list. Which of the following code segments will solve this problem for your teacher?

d. index ← 1 REPEAT LEN(app.grades) TIMES { app.grades[index] ← app.grades[index] + 5 IF(index = LEN(app.grades)) { app.grades[index] ← app.grades[index] + 2 } index ← index + 1 }

What gets printed after the code below is run? languages = [ 'python', 'spanish', 'english' ] language = languages.pop(1) print(language)

d. 'spanish'

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

d. 2

Which of the following will NOT be printed? for i in range(2, 5): print(i)

d. 5

Which of the following is not a valid property for Labels? a. border b. italic c. font Selected:d. All of these are valid properties for Labels.

d. All of these are valid properties for Labels.

What shapes are drawn in the following pumpkin? (Don't include the background!)

d. Ovals, Lines, Polygons

The following code has a logical error. The program should draw two circles centered where the mouse is released, if the mouse is in the bottom half of the canvas. Which answer choice contains the code to fix the error? PROCEDURE onMouseRelease(x, y) { IF(mouseY > 200) { Circle(mouseX, mouseY, 60, fill='blue') Circle(mouseX, mouseY, 30, fill='green') } }

d. Replace the function definition with:PROCEDURE onMouseRelease(mouseX, mouseY)

Which function gets called if we call h(False)? def h(isSunny): if (isSunny == True): wearHat() else: bringUmbrella()

d. h and bringUmbrella

Which of the following correctly creates a list of the numbers 1, 2, 3, 4, and 5?

d. numbers = [1, 2, 3, 4, 5]

What does the mystery function do in the code snippet below?def mystery(x, y): if x < y: return x else: return ya = mystery(10, 14)b = mystery(82, 28)print(a)print(b)

d. returns the smaller of two values passed to it

Which of the following will return True if x is odd?

d. x % 2 == 1

Question 4 Which shapes remains visible in the group after we press and release the mouse? g = Group() r = Rect(10, 10, 200, 200, fill='blue') s = Star(200, 200, 30, 5, fill='purple') c = Circle(100, 100, 5, fill='red') o = Oval(100, 100, 20, 20, fill='green') g.add(r) g.add(s) g.add(c) g.add(o) def onMousePress(x, y): g.remove(r) o.visible = False def onMouseRelease(x, y): g.add(r) g.remove(c)

r s

What can we call to get a random value from the list colorList?

random.choice(colorList)

What can we call to get a random position on the canvas?

random.randint(0, 400)

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

x


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

Mrs. Moroney's Math Final Review

View Set

Chapter 6 Introduction to Business

View Set

Speech Chapter 7. Gathering Materials

View Set

Unit 3: Principles of the Scientific Method: Validity and Control Book

View Set

PrepU quizzes Chapter 35: Comfort and Pain Management

View Set