Computer Programming Lab - Exam 1

0.0(0)
Studied by 0 people
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/24

flashcard set

Earn XP

Description and Tags

Variables & types , conditionals, booleans, functions, loops, & data structures (strings, lists, dictionaries, & tuples)

Last updated 7:09 AM on 10/8/26
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai
Chat

No analytics yet

Send a link to your students to track their progress

25 Terms

1
New cards

String (str)

Can be letters, words, sentences, or numbers enclosed in quotes.

Ex:

message = ‘Hello, world!’

2
New cards

Integer (int)

A data type that can be any whole number but not decimals.

Ex:

fav_number = 9

3
New cards

Float

A decimal

Ex:

month = 10.0

4
New cards

Boolean (bool)

A variable that can either be True or False.

Ex:

will_ace_exam = True

5
New cards

Local Variable

A variable defined inside functions.

6
New cards

Global Variable

A variable defined outside functions and can be “seen”/used by any function.

7
New cards

List

A sequence of values.

Can be ints, floats, strings, bools, & other lists.

Lists are mutable.

Uses square brackets - [ ]

Ex:

numbers = [1, 2, 3]

8
New cards

Dictionary (dict)

Has key-value pairs - key : value.

Can be ints, floats, strings, & a value can be a list.

Dictionaries are mutable.

Uses curly brackets { }

Ex:

songs = {‘LOONA’ : ‘High High’, ‘DREAMCATCHER’ : ‘Jazz Bar’}

9
New cards

Tuple

Tuples are immutable lists. Need to create a new tuple to “edit” it.

Uses parentheses ( )

Ex:

greetings = (‘hello’, ‘hola’, ‘bonjur’)

10
New cards

Loops

Used to repeat something over and over again.

11
New cards

While Loop

Repeats until a condition is no longer True and becomes False.

Has uncertainty.

Ex:

while CONDITION:
BODY

12
New cards

For Loop

Repeats a condition in a pre-defined group of items.

Need to create a new variable (name is related to the singular item).

Ex:

for ELEMENT in GROUP:
BODY

13
New cards

Break

Used to stop a loop from continuing/leave the loop early.

14
New cards

Continue

Ignores the rest of the BODY for the current element. Then, skips to the next element in the body.

15
New cards

Range

Gives a sequence of numbers.

Starts from 0 and increments by default.

Ex:

range(3) = [0, 1, 2]
range(start, end, increment) - range(1, 7, 2) = [1, 3, 5]

range(start, end, decrement) - range(3, 0, -1) = [3, 2, 1]

16
New cards

Length (len)

A built-in function that returns the number of characters in a string.

Ex:
fruit = ‘banana’
len(fruit)
6

17
New cards

Slice

Returns a segment of a string.

Can be the front, back half, everything, or empty.

Starts at index 0 and excludes the last character.

[:9], [9:], [ ], [9:9]

Ex:
[starting letter # : ending letter #]
fruit[:3]
‘ban’

18
New cards

Append

Adds new element to the end of a list.

Ex:
list.append(element)

19
New cards

Sort

Sorts a list alphabetically or from low to high.

Ex:
list.sort() - works only w/ lists - doesn’t modify original list
sorted() - works w/ anything - makes a new list

20
New cards

String Concatenation +

Joins strings without adding a space in between.

21
New cards

String Concatenation ,

Combines strings and automatically adds a space in between.

22
New cards

If Statement

Evaluates a condition (True or False) and executes the specified block of code if the condition is True.

Ex:
if CONDITION:
BODY

23
New cards

If/Else Statement

Evaluates a condition (True or False) and executes the 1st block of code if the condition is True, if not then it executes the 2nd block.


Ex:
if CONDITION:
BODY 1
else:
BODY 2

24
New cards

Else If Statement (elif)

Used to check multiple conditions sequentially.

Ex:
if condition_1:
elif condition_2: - checks if condition_1 is False AND condition_2 is True
else:

25
New cards

Define (def)

Used to start a function definition.

Ex:
def function_name:

return result


def function_name(parameters):

return result