Programming Concepts 005 A Flashcards

1
Q

What does this output?

def character(**kwargs):
print(f”{kwargs[“name”]}”)
print(f”{kwargs[“weapon”]}”)
print(f”{kwargs[“health”]}”)

character(name=”Owen”,
weapon=”Sword”,
health=75)

A

Owen
Sword
75

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What do keyword arguments do?

A

Using a keyword argument allows for the user to specify different variables to be used in the function.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How does linear search work?

A

It works by looping through the list iteratively and checking each value to see if the specified value exists.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is the main limitation of binary search?

A

It requires the dataset you are using to be sorted.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is this an example of?

def bin_search(items, target):
low = 0
high = len(items) - 1

while low <= high:
    mid = (low + high) // 2
    if items[mid] == target:
        return True  
    elif items[mid] < target:
        low = mid + 1
    else:
        high = mid - 1

return False
A

Binary search

How well did you know this?
1
Not at all
2
3
4
5
Perfectly