APCSP FINAL

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

What is the proper format for a single line comment in Karel? # This is a comment // This is a comment /* This is a comment This is a comment

# This is a comment

What is the last thing printed by the following program? start = 30 stop = 10 for i in range(start, stop - 1, -5): if i % 2 == 0: print(i * 2) else: print(i) 10 20 30 60

20

What is the value of num after this code runs? shapes = ["triangle", "square", "hexagon", "circle", "pentagon"] num = len(shapes) 0 4 5 35

5

How many total times will Karel move in this program? move() for i in range(5): move() put_ball() 1 5 6 7

6

What will the following program print when run? for j in range(2): for i in range(6, 4, -1): print (i) 4 5 4 5 6 5 4 6 5 4 0 2 6 4 6 5 6 5

6 5 6 5

What is wrong with this for loop? for i in range = 5; move() A. The for loop uses a semicolon(;) instead of colon(:) B. It should say range(5) instead of range = 5 A B A and B The for loop is correct

A and B

Why do we write functions? I. Make our code easier to understand by giving a readable name to a group of instructions II. Avoid writing repeated code III. Make our code reusable II and III I only I and II I, II, and III

I, II, and III

The following code continually asks the user for a password until they guess the correct password, then ends. But there is one problem. 1 SECRET_PASSWORD = "karel" 2 3 while True: 4 password = input("Enter your password: ") 5 if password == SECRET_PASSWORD: 6 print("You got it!") 7 print("Incorrect password, please try again.") Which of the following will fix this program? Change the True in line 3 to be password != SECRET_PASSWORD so that the program doesn't loop infinitely Change the True in line 3 to be password == SECRET_PASSWORD so that the program doesn't loop infinitely Add a break; statement after line 6 so that the program doesn't loop infinitely Put line 7 inside of an else statement

Add a break; statement after line 6 so that the program doesn't loop infinitely

What is the output of the following program: (Assume the user enters 'Florence' then 'Fernandez'.) first_name = input("What is your first name? ") last_name = input("What is your last name? ") whole_name = first_name + last_name; print (whole_name) Fernandez Florence Florence Fernandez FlorenceFernandez Florence Fernandez

FlorenceFernandez

What does the mystery function do? def mystery(): while no_balls_present(): move() Karel moves until it is on a ball Karel moves once if there is no ball present Karel moves until it puts down a ball Karel checks if there is no ball on the current spot and then moves once

Karel moves until it is on a ball

What's wrong with this code? def go(): move() move() def go(): move() move() move() go() go() The go function is called twice The go function has a syntax error The go function has been defined twice go is not a command that Karel understands

The go function has been defined twice

In the following code: size = 20 x = 100 y = 200 ball = Circle(size) circle.set_position(x, y) What is the meaning of the x variable? The x coordinate of the left side of a box that would hold the circle The x coordinate of the right edge of the circle The radius of the circle The x position of the center circle

The x position of the center circle

How many times will the following program print "hello"? i = 0 while i < 10: print("hello") 10 11 9 This code will loop infinitely

This code will loop infinitely

The following code should draw a circle on the screen. def draw_circle(x, y, radius): circle = Circle(radius) circle.set_position(x, y) Python But when we run this code, we don't see the circle. What is missing? Since we are trying to create a circle, we need to use the create_circle command. The code will have an error need to define the position when you create the the circle To add the circle to the canvas, you need to use the circle.add() command To add the circle to the canvas, you need to use the add(circle) command

To add the circle to the canvas, you need to use the add(circle) command

We want to simulate constantly flipping a coin until we get 3 heads in a row. What kind of loop should we use? For loop While loop Loop and a half Infinite loop

While loop

The following program should draw a circle on the screen def draw_circle(x, y): circle = Circle(100) circle.set_position(x, y) Python But when we run this code, we don't see the circle. What is missing? Since we are trying to create a circle, we need to use the create_circle command. The code will have an error since you need to define the color. You need to add the circle with the circle.add() command. You need to add the circle with the add(circle) command.

You need to add the circle with the add(circle) command.

Which of the following lines of code will cause an error? Use the following definition of ages: ages = (12, 5, 8) ages = ages + (1, 3, 5) print (ages[2]) ages = ages[2:] ages[0] = 3

ages[0] = 3

What does this code snippet print? fruit = ["b", "n", "n"] print ("a".join(fruit)) bnn ba na na banan banana

banan

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? print_three_times def print word

word

What kind of data structure is user_data in the following declaration? user_data = ["TJ", 24, "artLover123"] Tuple List String 2d List

list

If you were given the following variables: distance = 2 time = 30 What line of code would print the speed in km/hr if the distance is given in km and the time is given in minutes? (Speed = distance/time) print(distance/(time/60)) print(distance/time) print(distance*(time*60)) print(distance*time)

print(distance/(time/60))

What kind of data structure is user_data in the following declaration? user_data = ("TJ", 24, "artLover123") Tuple List String 2d List

tuple

Which of the following choices is a properly formed Python variable name, meaning it is both legal in the Python language and considered good style? user_age User_Age user_Age userAge

user_age

If you wanted to use the following code to draw a circle to the canvas with the radius, and x and y coordinates given by the user, how would you ask for this information? circle = Circle(radius) circle.set_position(x, y) x = input("What is the x coordinate? ") y = input("What is the y coordinate? ") radius = input("What is the radius of the circle? ") x = int(input("What is the x coordinate? ")) y = int(input("What is the y coordinate? ")) radius = int(input("What is the radius of the circle? ")) x = input("What is the x coordinate? ") y = input("What is the y coordinate? ") radius = int(input("What is the radius of the circle? ")) x = int(input("What is the x coordinate? ")) y = int(input("What is the y coordinate? ")) radius = input("What is the radius of the circle? ")

x = input("What is the x coordinate? ") y = input("What is the y coordinate? ") radius = int(input("What is the radius of the circle? "))

We want to position a Circle on our screen to be at a random position, but we want to keep the entire shape on the screen. Which of the following will accomplish this given the following function? (Assume SIZE, HEIGHT, and WIDTH are properly defined) def draw_circle(x, y, radius): circle = Circle(radius) circle.set_position(x, y) add(circle) x = random.randint(0,WIDTH) y = random.randint(0,HEIGHT) draw_circle(x, y, SIZE) x = random.randint(SIZE,WIDTH-SIZE) y = random.randint(SIZE,HEIGHT-SIZE) draw_circle(x, y, SIZE) x = random.randint(0,HEIGHT) y = random.randint(0,WIDTH) draw_circle(x, y, SIZE) x = random.randint(SIZE,HEIGHT-SIZE) y = random.randint(SIZE,WIDTH-SIZE) draw_circle(x, y, SIZE)

x = random.randint(SIZE,WIDTH-SIZE) y = random.randint(SIZE,HEIGHT-SIZE) draw_circle(x, y, SIZE)


Conjuntos de estudio relacionados

Chapter 07: Health Promotion of the Newborn and Family

View Set

Adult Health Final Exam Questions

View Set

Taxation of Life Insurance and Annuity Quizzes

View Set

AP Bio chapters 14 and 15 review questions

View Set

Entrepreneurship - Chapters 7 & 8

View Set

3 - Life Insurance Policies - Provisions, Options and Riders (Exam 1)

View Set

PSY 350 midterm 1 + 2, PSY 350 new material for final

View Set

care across the Lifespan Prep U Final exam

View Set

Chapter 16 Practice Quiz Questions

View Set

2.7 Personal Uses of Life Insurance

View Set

Exercise 15: Histology of Nervous Tissue

View Set