CSCI Midterm
I. BASIC PYTHON CONCEPTS
Flashcard 1
Q: How do you assign a value to a variable in Python?
A: Use variable_name = value.
Flashcard 2
Q: Difference between int, float, and str?
A: int = whole numbers, float = decimals, str = text.
Flashcard 3
Q: How do you concatenate two strings?
A: "hello" + "world".
Flashcard 4
Q: What does input() do?
A: Reads user input and returns it as a string.
Flashcard 5
Q: What does type() do?
A: Shows the data type of a value or variable.
Flashcard 6
Q: Convert "25" to an integer.
A: int("25").
Flashcard 7
Q: How do you write a comment in Python?
A: Use #.
Flashcard 8
Q: Convert a string to lowercase.
A: s.lower().
Flashcard 9
Q: How do you find the length of a string or list?
A: len().
Flashcard 10
Q: What does len() return?
A: Number of items/characters.
II. CONTROL FLOW
Flashcard 11
Q: What’s the purpose of an if-else statement?
A: To run different code depending on a condition.
Flashcard 12
Q: What is elif used for?
A: Multiple conditions when if isn’t true.
Flashcard 13
Q: Difference between and and or?
A:
and: both conditions must be true
or: at least one must be true
Flashcard 14
Q: What does not do?
A: Reverses a Boolean value.
Flashcard 15
Q: Structure of a while loop?
A:
while condition:
code
Flashcard 16
Q: How does a for loop work?
A: Iterates over items in a sequence (list, string, range).
Flashcard 17
Q: Purpose of break?
A: Stops a loop immediately.
Flashcard 18
Q: Purpose of continue?
A: Skips to the next loop iteration.
Flashcard 19
Q: Print numbers 1–10 using a loop.
A:
for i in range(1, 11):
print(i)
III. DATA STRUCTURES
Flashcard 20
Q: Difference between list and dictionary?
A: List uses indexes; dictionary uses key-value pairs.
Flashcard 21
Q: Create an empty list.
A: [] or list().
Flashcard 22
Q: Append to a list.
A: lst.append(item).
Flashcard 23
Q: Remove last item in a list.
A: lst.pop().
Flashcard 24
Q: Access first list element.
A: lst[0].
Flashcard 25
Q: Access last list element.
A: lst[-1].
Flashcard 26
Q: Reverse a list using slicing.
A: lst[::-1].
Flashcard 27
Q: Add an item to a dictionary.
A: d[key] = value.
Flashcard 28
Q: Check if value exists in list.
A: value in lst.
Flashcard 29
Q: Combine lists.
A: list1 + list2.
IV. STRING MANIPULATION
Flashcard 30
Q: Check if string contains substring.
A: "cat" in s.
Flashcard 31
Q: Count vowels in a string (core idea).
A: Loop through characters and count "aeiou".
Flashcard 32
Q: Split string into words.
A: s.split().
Flashcard 33
Q: Remove whitespace on ends.
A: s.strip().
Flashcard 34
Q: Reverse a string.
A: s[::-1].
Flashcard 35
Q: What does find() do?
A: Returns index of substring or -1 if not found.
Flashcard 36
Q: Replace substring.
A: s.replace("old", "new").
Flashcard 37
Q: Convert to uppercase.
A: s.upper().
Flashcard 38
Q: Check if string is numeric.
A: s.isdigit().
Flashcard 39
Q: Format a string.
A:
f"Hello {name}"
V. FUNCTIONS & ALGORITHMS
Flashcard 40
Q: Purpose of return?
A: Sends a value back from a function.
Flashcard 41
Q: How to define a function?
A:
def function_name(params):
code
Flashcard 42
Q: Function that returns sum of two numbers.
A:
def add(a, b):
return a + b
Flashcard 43
Q: Function that takes list and returns average.
A: sum / length.
Flashcard 44
Q: What is an algorithm?
A: Step-by-step process to solve a problem.
Flashcard 45
Q: Find minimum in a list?
A: Loop through, track smallest so far.
Flashcard 46
Q: Sum elements in a list?
A: Use sum(lst) or loop and add.
Flashcard 47
Q: Convert Celsius → Fahrenheit.
A: F = C * 9/5 + 32.
Flashcard 48
Q: What is a local variable?
A: A variable created inside a function.
Flashcard 49
Q: Number of parameters in def t(a,b,c,d)?
A: 4.
VI. SEARCHING & SORTING
Flashcard 50
Q: How does binary search work?
A: Repeatedly splits sorted list in half to find a target.
Flashcard 51
Q: What happens if list is not sorted?
A: Binary search fails / returns incorrect results.
Flashcard 52
Q: How does insertion sort work?
A: Builds sorted list one element at a time by inserting into correct position.
Flashcard 53
Q: Why sort a list?
A: Makes searching faster, organizes data.
Flashcard 54
Q: Alternatives to insertion sort.
A: Bubble sort, Selection sort, Merge sort, Quick sort.