Programming Concepts 005 A Flashcards
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)
Owen
Sword
75
What do keyword arguments do?
Using a keyword argument allows for the user to specify different variables to be used in the function.
How does linear search work?
It works by looping through the list iteratively and checking each value to see if the specified value exists.
What is the main limitation of binary search?
It requires the dataset you are using to be sorted.
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
Binary search