Algorithm Python code:
target_value = 42
while True:
   try:
      user_input = int(input("Enter the correct value: "))
      if user_input == target_value:
          print("Congratulations! You answered correctly.")
          break
      else:
          print("Try again.")
   except ValueError:
      print("That wasn't a number! Try again.")
2. What is abstraction?
The process of reducing complex systems by pointing out the crucial
components and hiding the unneeded details is known as abstraction.
Example:
High level of abstraction: Using a calculator to perform arithmetic
operations without needing to understand the underlying algorithms or
circuitry.
Low level of abstraction: Writing assembly language code to directly
control hardware components of a computer.
3. Of the following which are considered mobile devices:
a. Cell phone
d. Tablet
4. Define:
a. Scrum: Scrum is an agile project management framework used to
manage complex software development.
b. Scrum master: The Scrum master is a facilitator who ensures that
the Scrum team follows the Scrum process, removes obstacles, and
helps the team to be more effective.
c. User story: A user story is a brief, non-technical description of a
feature or functionality from an end-user perspective, used in agile
software development.
d. Backlog: The backlog is a prioritized list of tasks, requirements, or
user stories that need to be addressed in a software project.
e. Sprint task list: The sprint task list is a subset of items from the
backlog that the Scrum team commits to completing during a sprint.
f. Stand up meeting: A stand-up meeting is a short daily meeting where
team members discuss progress, plans, and any obstacles they are
facing.
g. User Interface (UI): The user interface is the graphical or visual part
of a software application that allows users to interact with the system.
h. API (Application Programming Interface): An API is a set of rules and
protocols that allows different software applications to communicate
with each other.
i. Version control: Version control is a system that tracks changes to
files and documents over time, allowing users to access previous
versions and manage changes collaboratively.
j. Pseudocode: Pseudocode is a high-level description of a computer
program or algorithm that uses natural language elements to outline
the logic of the program.
k. Event driven: Event-driven programming is a programming paradigm
where the flow of the program is determined by events such as user
actions or system notifications.
5. Define and provide an example:
a. Function/Procedure: A function or procedure is a reusable block of
code that performs a specific task. Example:
python
Copy code
def greet(name):
   print("Hello, " + name)
b. Call statement: A call statement is used to execute a function or
procedure. Example:
python
Copy code
greet("Alice")
c. Assignment operator: The assignment operator (=) is used to assign
a value to a variable. Example:
python
Copy code
x = 10
d. Parameter: A parameter is a variable in a function definition.
Example:
python
Copy code
def greet(name):
  print("Hello, " + name)
(Here, name is a parameter)
e. Variable: A variable is a placeholder for storing data in a computer
program. Example:
python
Copy code
x = 10
f. Decision structure: A decision structure allows the program to make
decisions based on certain conditions. Example:
python
Copy code
if x > 0:
    print("Positive")
g. Iteration: Iteration is the process of repeating a set of instructions a
certain number of times or until a condition is met. Example:
python
Copy code
for i in range(5):
   print(i)
h. For loop: A for loop is a control flow statement for iterating over a
sequence of elements. Example:
python
Copy code
for i in range(5):
   print(i)
i. While loop: A while loop is a control flow statement that repeatedly
executes a block of code as long as a condition is true. Example:
python
Copy code
while x > 0:
    print(x)
j. List: A list is a data structure that stores a collection of items in a
specific order. Example:
python
Copy code
my_list = [1, 2, 3, 4, 5]
k. Concatenation: Concatenation is the process of combining two or
more strings into one. Example:
python
Copy code
result = "Hello, " + "world"
l. Local variable: A local variable is a variable that is defined inside a
function and is only accessible within that function. Example:
python
Copy code
def my_function():
  x = 10
  print(x)
m. Global variable: A global variable is a variable that is defined
outside any function and is accessible from anywhere in the program.
Example:
python
Copy code
x = 10
def my_function():
   print(x)
n. Modulus: The modulus operator (%) returns the remainder of a
division operation. Example:
python
Copy code
result = 10 % 3
o. Element: An element is an individual value in a collection like a list
or an array. Example:
python
Copy code
my_list = [1, 2, 3]
element = my_list[0]
p. Index: An index is a position number that specifies the location of an
element in a list or array. Example:
python
Copy code
my_list = [1, 2, 3]
index = my_list.index(2)
q. Conditional statement: A conditional statement is used to perform
different actions based on different conditions. Example:
python
Copy code
if x > 0:
    print("Positive")
elif x == 0:
    print("Zero")
else:
    print("Negative")
r. Relational operator: Relational operators compare two values.
Example:
python
Copy code
if x > y:
    print("x is greater than y")
s. Logical operator: Logical operators combine multiple conditions.
Example:
python
Copy code
if x > 0 and y > 0:
    print("Both x and y are positive")
t. Accumulator: An accumulator is a variable that stores a running
total. Example:
python
Copy code
total = 0
for i in range(5):
   total += i
u. Class: A class is a blueprint for creating objects (a particular data
structure). Example:
python
Copy code
class Dog:
   def __init__(self, name):
     self.name = name
v. Objects: An object is an instance of a class. Example:
python
Copy code
my_dog = Dog("Buddy")
w. Methods: Methods are functions defined inside a class that operate
on objects of that class. Example:
python
Copy code
class Dog:
   def __init__(self, name):
     self.name = name
   def bark(self):
     print("Woof!")
my_dog.bark() # Output: Woof!
6. Explain each data type:
a. Integer: A whole number, positive or negative, without decimals.
Example: x = 5
b. Float: A number that has a decimal point. Example: y = 5.0
c. String: A sequence of characters enclosed in quotes. Example: name
= "Alice"
d. Boolean: A data type with only two possible values: True or False.
Example: is_valid = True
7. Why do we use procedures?
Procedures help us write more flexible, easily readable, and
maintainable code by hiding it into reusable blocks. Procedures assist
in managing difficulty, preventing copying, and improve code
organization.
8. Explain the difference of waterfall design and agile development?
Which is better and why?
Waterfall Design: A careful and sequential process in which every stage
needs to be finished before moving on to the next. It is less adaptable
to changes and more solid.
Agile development is a slow, iterative process that promotes
collaboration, adaptability, and ongoing improvement. Even in later
stages of development, agile allows for changes.
Which is better and why?
Agile development is generally thought to be better because it
provides greater flexibility, enhances customer collaboration, and
reacts to changes more quickly. These characteristics result in software
that is of higher quality and happier customers.
9. What is wrong and why?
python
Copy code
age = int(input("Enter your age: "))
months = age * 12
print("you are " + months + " old")
What is wrong:
The expression months is an integer, and it cannot be concatenated
with strings directly.
Correct code:
python
Copy code
age = int(input("Enter your age: "))
months = age * 12
print("You are " + str(months) + " months old")
10. What is wrong and why:
python
Copy code
def sum(a, b, c):
  return a + b + c
print(sum(2, 12))
What is wrong:
The function sum expects three parameters, but only two are provided
in the call.
Correct code:
python
Copy code
def sum(a, b, c):
  return a + b + c
print(sum(2, 12, 5)) # Provide three arguments
11. What is sequencing and how does it affect an algorithm?
The precise order in which directions are carried out within a program
is known to as sequencing. Making sure that instructions are followed
in the right order and produce the intended result is known as proper
sequencing. Incorrect outcomes and logic errors can arise from wrong
sequencing.
12. Review the following code: What is wrong with it and why?
python
Copy code
total = 0
count = 0
for i in [10, 20, 30, 40, 50]:
   total = count + 1
   print("The value of i is:", i)
print("The sum of all the values is:", total)
What is wrong:
The variable total is being assigned count + 1 instead of accumulating
the sum of i.
count is not being used correctly, and total is not accumulating the
values.
Correct code:
python
Copy code
total = 0
for i in [10, 20, 30, 40, 50]:
   total += i
   print("The value of i is:", i)
print("The sum of all the values is:", total)
13. For a list provide the following:
a. How do you print only one element:
python
Copy code
my_list = [1, 2, 3]
print(my_list[1])
b. How do you add an item to a list:
python
Copy code
my_list = [1, 2, 3]
my_list.append(4)
c. What command is used to delete an item from a list:
python
Copy code
my_list = [1, 2, 3]
my_list.remove(2) # Removes the element 2 from the list
14. Fruit = ['apple', 'grape', 'pear']
a. Write the code to print the second item in the list:
python
Copy code
Fruit = ['apple', 'grape', 'pear']
print(Fruit[1]) # Prints 'grape'
15. Review the following code, what is wrong with it and why?
python
Copy code
items = [2, 3, 4.50, 5, 6, 2.5, 11]
for cost in items:
   total = 0
   total = total + cost
   print 'Your bill so far is $' + str(total) + '.'
What is wrong:
The total variable is being reset to 0 in each iteration.
The print statement syntax is incorrect for Python 3.
Correct code:
python
Copy code
items = [2, 3, 4.50, 5, 6, 2.5, 11]
total = 0
for cost in items:
   total += cost
   print('Your bill so far is $' + str(total) + '.')
16. What is the difference between each function and why does it
matter?
sequence:
python
Copy code
def sequence(stop):
   number_list = []
   for counter in range(stop):
      number_list.append(counter)
   return number_list
sequence2:
python
Copy code
def sequence2(stop):
   number_list = []
   counter = 0
   while counter < stop:
      number_list.append(counter)
      counter += 1
   return number_list
Difference:
sequence uses a for loop, which is simpler and more concise for
iterating a fixed number of times.
sequence2 uses a while loop, which is more flexible for cases where
the number of iterations is not known beforehand.
Why it matters:
Choosing between for and while loops depends on the specific use
case and can affect readability and performance.
17. What is the difference between high level languages and low level
languages?
High level languages: These abstract away a lot of hardware details
and are more similar to human languages. Some of the examples are
C++, Java, and Python. They are simpler to maintain, write, and read.
Low level languages: They offer less abstraction from the structure of
an instruction set on a computer and are closer to machine language.
Machine code and assembly language are two examples. While they
are more difficult to read and write, they provide more control over
hardware.18. What are comments and why and when are they
important
Comments are non-executable statements in code that explain what
the code does. They are important because they:
Improve code readability and understanding.
Help developers remember their thought process.
Assist in debugging and maintaining code.
Provide documentation for others who may work on the code in the
future.
19. What is the relationship between if, elif, and else
The if, elif, and else statements are used for conditional branching in
programming:
if: Executes a block of code if a specified condition is true.
elif: Stands for "else if" and checks another condition if the previous if
condition is false.
else: Executes a block of code if none of the preceding conditions are
true.