Computer Programming Reviewer
1. A programming construct used to iterate over a sequence of elements, executing a block of
code for each element in the sequence (For Loop)
2. A control flow statement that repeatedly executes a block of code as long as a specified
condition is true. ( While Loop)
3. A statement is used to skip the current iteration of a loop and move to the next iteration.
(Continue)
4. A statement is used to exit a loop permanently, regardless of the loop’s normal condition for
termination (Break)
5. The process of Decreasing the value of loop control variable (Decrement)
6. The process of increasing the value of a loop control variable (Increment)
7. A loop that continues to execute indefinitely because its termination condition is never.
(Infinite Loop)
8. This is the Boolean expression that determines whether the loop should continue executing or
not (Condition)
9. This is where you set the initial value for the loop control variable’s before entering the loop.
(Initialization)
10. A programming constructs that allow you to repeat a block of code multiple times (Loops)
1. You need to iterate over a list
21 – 25 FOR LOOP: Python script that iterates over a list of number and print each number
number = 5
while number <= 25:
print(number)
number += 5
for number in range(5, 26, 5):
print(number)
26 – 30. WHILE LOOP: Loops with break statement
numbers = [0,1,2,3,4,5,6,7,8,9,10,11]
for num in numbers:
if num > 5:
break
print(num)
print(“Loop Ended”)
numbers = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]
index = 0
while index < len(numbers):
num = numbers[index]
if num > 5:
break
print(num)
index += 1
print("Loop Ended")
31 – 35. WHILE LOOP: Print the names alphabetically
LIST_NAMES = ["SALAZAR", "SANTOS", "BALTAZAR", "COMO", "TOLENTINO","AGUBA",
"ANDAL" ]
#sort the list alphabetically
sorted_names = = sorted(LIST_NAMES)
#iterate over sorted names using for loop
for name in sorted_names
print(name)
LIST_NAMES = ["SALAZAR", "SANTOS", "BALTAZAR", "COMO", "TOLENTINO", "AGUBA",
"ANDAL"]
sorted_names = sorted(LIST_NAMES)
index = 0
while index < len(sorted_names):
print(sorted_names[index])
index += 1
36 – 40 WHILE LOOP : Calculate the average temperature of a material over time
temperature_readings = [25, 28, 30, 32, 27]
sum_temperature = 0
for temp in temperature_readings:
sum_temperature += temp
average_temperature= sum_temperature/len(temperature_readings)
print("Average Temperature", average_temperature)
index = 0
while index < len(temperature_readings):
sum_temperature += temperature_readings[index]
index += 1
average_temperature = sum_temperature / len(temperature_readings)
print("Average Temperature", average_temperature)
41 – 50. 10 one line code with built in function
print("Hi Love")
age = int("18")
high = max(15,10)
low = min(43, 23)
distance = abs(34)
place = str(100)
yes = bool(5)
sorted([1,5,7,8])
help()
exit()
51 – 60 syntax of defining a function in phyton
Def function_name(parameters):
# function body
return result
61 – 70 user defined function with multiple parameters
def greet(name, age):
print(f"Hello, {name}! You are {age} years old.")
# Example usage
greet("Alice", 30)
greet("Bob", 25)
71 – 80 user defined function with selection statements and loops
def process_numbers(numbers):
for number in numbers:
if number % 2 == 0:
print(f"{number} is even")
else:
print(f"{number} is odd")
# Example usage
process_numbers([1, 2, 3, 4, 5])