Matrimony Assignment 2
Matrimony Assignment 2
macOS
(i)app: This is the standard application bundle format
for macOS. It's a directory that contains the application's
executable file, along with other resources like images, libraries,
and settings.
(ii)pkg: This is a package file format for installing
applications on macOS. It's similar to the .msi format on Windows,
and it can contain multiple files and settings.
(iii)command: This is a shell script file for macOS. It's
used to run commands in the Terminal.
10) How can one stop the execution of a loop before it is completed?
Illustrate the difference between ‘break’ and ‘continue’ with an example.
To stop the execution of a loop before it is
completed, one can use the break statement. The break statement
terminates the loop entirely and transfers control to the code that
follows the loop. On the other hand, the continue statement skips the
current iteration of the loop and proceeds with the next iteration
without terminating the loop.
Example:
# Using 'break'
print("Using 'break':")
for i in range(1, 6):
if i == 4:
print(f"Loop breaks at i = {i}")
break # Exit the loop when i equals 4
print(f"i = {i}")
# Using 'continue'
print("\nUsing 'continue':")
for i in range(1, 6):
if i == 4:
print(f"Skipping i = {i}")
continue # Skip the rest of the loop when i equals 4
print(f"i = {i}")
Output:
Using 'break':
i=1
i=2
i=3
Loop breaks at i = 4
Using 'continue':
i=1
i=2
i=3
Skipping i = 4
i=5
11)Write the pseudo code to find the sum of the cubes of the first 9
positive integers.
PSEUDO CODE:
BEGIN
Initialize SUM as 0
FOR i FROM 1 TO 9 DO
Compute CUBE = i * i * i
Add CUBE to SUM
END FOR
OUTPUT "The sum of the cubes of the first 9 positive
integers is:", SUM
END
Explanation:
Initialization: Start with SUM = 0 to store the cumulative total.
Loop: Use a FOR loop to iterate through integers from 1 to 9.
Cube Calculation: Compute the cube of the current integer, i.
Accumulate: Add the cube to the running total, SUM.
Output: After the loop completes, display the result.
12) Write the pseudo code to check if a given 4-digit square number will
yield another square number by adding 1 to each digit. For example, if
2025 is the input, adding 1 to each digit yields 3136.
BEGIN
INPUT number (4-digit square number)
IF number is not a 4-digit number OR number is not a perfect square
THEN
OUTPUT "Invalid input"
EXIT
END IF
Convert number to a string representation for digit manipulation
Initialize new_number as an empty string
FOR each digit in the string representation of number DO
Add 1 to the digit
Append the result to new_number
END FOR
Convert new_number back to an integer
Compute square_root = √(new_number)
IF square_root * square_root = new_number THEN
OUTPUT "New number", new_number, "is a perfect square"
ELSE
OUTPUT "New number", new_number, "is NOT a perfect square"
END IF
END
For input 2025:
Add 1 to each digit: 2025 → 3136
Check if 3136 is a perfect square:
√3136 = 56
56² = 3136 (it's a perfect square)
Output: "New number 3136 is a perfect square."