Coding Khan Academy Test

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

1/51

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

52 Terms

1
New cards

integer

whole number, 5

2
New cards

float

decimal number, 21.4

3
New cards

string

text in quotes, “hi”

4
New cards

boolean

true/false

5
New cards

+ - * **

addition, subtraction, multiplication, exponentiation

6
New cards

/

float division

will have decimals

40/4 is 10.0

7
New cards

//

floor division, no decimals and rounding

41//4 is 10

8
New cards

%

modulus

remainder

41 % 4 = 1

9
New cards

assignment statement

stores a value in a variable

high_score = 10

10
New cards

print(x)

displays value x

11
New cards

input(x)

prompts the user

12
New cards

abs(x)

returns absolute value

13
New cards

round(x)

returns x rounded to nearest integer

14
New cards

round(x,y)

returns x rounded to yth decimal place

15
New cards

min(x,y)

returns smallest of values

16
New cards

max(x,y)

returns largest of values

17
New cards

len(x)

returns number of characters in string

18
New cards

typecasting

converting values from one data type to another

int() converts number to integer

float() converts it to a float

str() converts value to string

bool() converts to boolean

19
New cards

==

equal to

20
New cards

! =

not equal to

21
New cards

< > <= >=

less than

greater than

less than or equal to

greater than or equal to

22
New cards

and

is true if both conditions evaluate to true

23
New cards

or

is true if at least one conditions is true

24
New cards

not

is true if condition is false

25
New cards

if

starts a conditional

26
New cards

elif

branch of conditional

chains a condition onto an existing conditional

computer checks each branch until it finds a true one and executed it, skipping other branches left over

27
New cards

else

ends a conditional, used to fulfill other remaining cases

only if all other cases are false is it executed

28
New cards

import

import random

used to load an external module into a python file

to call it, write module name with . before writing function

random.randint(1,6)

29
New cards

while loops

repeats a block of code as long as condition is true

30
New cards

for loops

repeats for a specific amount of time

uses range function:

for count in range(6):

31
New cards

break

exits a loop early

execution skips remaining lines

32
New cards

continue

skips to next loop iteration, jumping to top

33
New cards

function

named block of code that performs a specific task

only executed when the function is called

some have return statements, others have print

to create, do: def function(parameters):

to call it: use name and parentheses and input arguments

add_tax(receipt)

34
New cards

lists

ordered collection or sequence of elements

can be any type of data, separated by commas

organize with brackets

35
New cards

indexing

describes an element based on its position in the list

location

first is always 0

last can be found with len(list) - 1

len determines number of items in an object, or list in this case

list = [1, 2, 3]

print(len(list))

result is 3

36
New cards

slicing

subset of list using start and end index

start is inclusive, end is exclusive

scores = [1, 2, 3, 4]

top_scores = scores[0:3]

top_scores= [1, 2, 3]

37
New cards

list assignment

updates element at specific index (location)

dress_colors = [“blue”, “red”, “green”]

dress_colors[2] = “brown”

dress_colors = [“blue”, “red”, “brown"]

38
New cards

in operator

checks if specific element exists in a list

evaluates to True or False

if “blue” in dress_colors:

(indent) print(“Yes”)

39
New cards

list iteration

for loops can iterate over every element of a list in order

will print the list out

iteration by index requires range, starting at 0 to end of list

40
New cards

for i in range

used to create a loop that iterates for a certain amount of itmes

for i in range(start, stop, step):

do the code

for i in range(2, 10, 2)

print(I)

you will get 2 4 6 8 printed

41
New cards

append(element)

adds element to end of list

42
New cards

insert(i, element)

inserts element at index I, only shifting, not replacing

43
New cards

pop()

removes last item of list

44
New cards

pop(I)

removes element at certain spot, NOT a specific value

45
New cards

upper()

makes characters uppercase

46
New cards

lower()

makes characters lowercase

47
New cards

strip()

removes leading or trailing spaces from a string

48
New cards

strip(chars)

removes leader or trailing chars from a string

49
New cards

split()

splits string based on spaces in a list of words

50
New cards

split(chars)

splits a string based on chars in a list of words

51
New cards

join(list)

inserts the string between each part of a list and connects it all into one string

52
New cards

remove()

removes the value in the parenthesis from the list