AP Comp. Sci. Principals Semester Test

0.0(0)
studied byStudied by 0 people
0.0(0)
full-widthCall with Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/25

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai

No study sessions yet.

26 Terms

1
New cards

Basic Commands

Built-in Karel commands, case sensitivity matters, move(), turn_left(), put_ball()

2
New cards

Functions

Defining new commands, are created using the ‘def’ keyword. The structure is ‘def function_name():’ followed by an indented block of code. Helps break down programs into smaller groups (top-down design), avoid repeating code, and make the program more readable.

3
New cards

Function Definition and Calling

A function must be defined once before it can be called multiple times in the program.

4
New cards

Syntax Error

Defining the same function twice

5
New cards

Top-Down Design

This is a method of designing a program by starting with the biggest problem and breaking it down into smaller, easier-to-solve sub-problems (functions)

6
New cards

Comments

A single-line that is created using the pound sign (#)

7
New cards

Indentation

Is mandatory and is used to define a code block (or “body”) for functions, ‘for’ loops, ‘while’ loops, and ‘if’ statements. It clearly shows the structure of the code and what commands belong together

8
New cards

‘for’ Loop

Used to repeat a fixed set of commands a fixed number of times. Ideal for tasks where you know the exact number of repetitions. Ex: for I in range():

9
New cards

‘while’ Loop

Used to repeat commands as long as a certain condition is true. The loop continues to run until the condition becomes false. Ex: while facing_north():

10
New cards

if/else

Used to run a command or block of code only if a condition is true. The else block runs only if the condition is false. Ex: if facing_north(): move() else: face_north()

11
New cards

Conditions

These are commands that return a “true” or “false” value and are used in ‘while’ and ‘if’ statements. Ex: balls_present(), no_balls_present()

12
New cards

Counting repeats

When a command is inside a ‘for I in range (n):’ loop, it executes n times. If the command is outside the loop, it executes once

13
New cards

The Last Spot Problem (cleanup Karel)

when a ‘while front_is_clear():’ loop is used to reaverse a row, the loop stops before Karel moves onto the final location. Any action that needs to be performed on the final spot must be handled by any ‘if’ statement placed after the ‘while’ loop.

14
New cards

Variable Assignment

The correct way to store a value is using the assignment operator (variable_name = value). The variable name must start with a letter or underscore and is typically written in all lowercase with underscores.

15
New cards

Snake Case

All lowercase with underscores

16
New cards

‘getting’ input

always reads user input as a string

17
New cards

string

text

18
New cards
19
New cards

Data type conversion

To use user input as a number in math calculations, you must convert the string to an integer using the int() function: number_var = int(input(“prompt: “)).

20
New cards

Output and Concatenation

the print() function displays output. Using the + operator on 2 strings results in string concatenation.

21
New cards

String Concatenation

Joining 2 strings together without a space EX: “Hello” + “World” = “HelloWorld”

22
New cards

Canvas Coordinates

The standard graphics canvas uses the Cartesian coordinate system.

23
New cards

Circle Placement

When using the ‘circle’ object ‘set_position(x, y)’ , the ‘(x, y)’ coordinates define the center of the cirlce

24
New cards

Modulus %

Calculates the remainder of a division Ex: 18 ‘MOD’ 4 is 2

25
New cards

Input()

Used to read a value from the user

26
New cards

Displace()

Used to show output