Ap Computer Science Principles - Unit 1

0.0(0)
studied byStudied by 21 people
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/21

flashcard set

Earn XP

Description and Tags

Karel in Codehs

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

22 Terms

1
New cards

regular karel knows…

4 commands:

  • move()

  • turn_left()

  • put_ball()

  • take_ball()

2
New cards

rows:

columns:

streets

avenues

3
New cards

a function

a way to teach karel a new word

def name of function ():

indent + command

4
New cards

why do we use functions?

  • break program into smaller parts

  • make the program easier to understand

5
New cards

naming your function

  • start with a letter, no spaces

  • snake_case

    • lowercase and use underscore

  • start with an action word and should sound like a command

6
New cards

top down design

breaking a big problem down into smaller parts

  • helps to solve complicated problems

  • allows to collaborate and split tasks

7
New cards

comments

  • break down your problem

  • make your code clear to others

  • multi-line: ‘‘‘comment’’’

  • single line: #comment

  • preconditions: assumptions we make, and what must be true

  • postconditions: what should be true after the function is called

8
New cards

abstraction

managing complexity by “abstracting away” info and details

  • to focus on more relevant details

9
New cards

SuperKarel

two new functions:

  • turn_right()

  • turn_around()

10
New cards

API

application programming interface

  • is a set of tools for building programs

11
New cards

For loops

  • repeat a code for a fixed number of times

    • for i in range(count):

      • code to execute

12
New cards

if statements and conditionals

  • a function that returns a true/false answer

    • if condition:

      • code

13
New cards

if/else statements

these statements let karel handle diffferent types of worlds

if conditions:

# code if condition is true

else:

# code to run otherwise

14
New cards

while loops

allows us to repeat a section of code as long as it is true

  • while condition:

    • # code to execute while condition is true

15
New cards

control structures

  • ask questions

  • repeat code

16
New cards

debugging strategies

  • attention to detail

  • even smaller syntax error could be a problem

  • question all your code

  • small errors

    • typos in variable names

    • syntax, loops, if statements

    • code that isn’t what you meant

    • mix-ups

17
New cards

debugging with error messages

syntax error:

runtime error:

logic error:

program doesn’t start running

program starts but then crashes

program starts, but doesn’t do what you want

18
New cards

algorithms

self-contained, step by step set of instructions

19
New cards

programs

implementation of algorithms into a computer

20
New cards

3 building blocks

sequencing:

iteration:

selection:

step by step instructions in the order they are given

repetition of instructions a specified number of times'

using a condition to determine which part is executed

21
New cards

pseudocode

writing out the algorithm in english- like code to help us figure out how to write the program

22
New cards

parameters

inputs into functions

  • paint(color[‘red’])

  • color_is(color[‘red’])