Assignment 1
Assignment 1
1. Start
2. Enter a number (let's say "num").
3. If number is even:
a. Assign result to num * num (num squared).
Else:
a. Assign result to num * num * num (num cube).
4. Produce the outcome.
5. Inquire if the user wishes to proceed:
A. if yes, go to step 2.
B. If not, stop the application.
6. Stop
Task 2: Flowchart Creation Design a flowchart that outlines the logic for a
user login process. It should include conditional paths for successful and
unsuccessful login attempts, and a loop that allows a user three attempts
before locking the account.
Task 3: Function Design and Modularization Create a document that
describes the design of two modular functions: one that returns the factorial
of a number, and another that calculates the nth Fibonacci number. Include
pseudocode and a brief explanation of how modularity in programming helps
with code reuse and organization.
Factorial of n
Pseudocode:
def factorial(number):
if number == 0:
return 1
else:
return number * factorial(number - 1)
Described
This function performs a recursive calculation of a number's factorial. It determines whether
the number is zero, in which case it returns one because zero has a factorial of one. If not, it
calls itself recursively, decrementing the number by 1, until it reaches the base case.
Fibonacci Pseudocode:
def fibonacci(n):
if n == 0:
return 0
elif n == 1:
return 1
else:
return fibonacci(n - 1) + fibonacci(n - 2)
Described
The nth Fibonacci number is determined recursively using this function, as explained below.
Since the Fibonacci sequence begins with 0 and 1, it checks to see if n is 0 or 1. If n is 1, it
returns 0 or 1, respectively. If not, it calls itself recursively with n decremented by 1 and n
decremented by 2, adding the results to obtain the nth Fibonacci number.
Modularity in Programming
1 Code reuse: It is the practice of reusing modular functions in various sections of a program
or even in separate applications. For example, you can reuse the above-designed factorial and
Fibonacci functions whenever you need to perform factorial or Fibonacci computations.
3 Enhanced Readability: Because each module in a modular program has a distinct purpose and
can be examined separately, they are frequently simpler to read and comprehend. This
facilitates other developers' understanding and contribution to the source.