SET B Flashcards

1
Q

List three types of relationships used in ERD and give a brief description of each.

A
  1. One-to-one(1:1) - A single entity instance in one entity class is related to a single entity instance in another class.
  2. One-to-many(1:M) - A single entity instance in one entity class is related to multiple instances in another.
    3.Many-to-many(M:M) - Multiple instances in one entity class are related to
    multiple instances in another.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Enumerate the differences between Conceptual, Logical, and Physical data models.

A

-Conceptual Data Model: Focuses on main entities and their relationships.

Components are entities and relationships.

-Logical Data Model: Focuses on tables, columns, and relationships.

Components are entities and relationships, attributes and keys.

-Physical Data Model: Focuses on tables, columns, data types, indexes, and constraints.

Components are tables, columns, data types, indexes and constraints.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Analyze the following Python code and explain what it does. Additionally,
suggest how you would improve it:
This code basically checks whether the given number is a prime or not.

A

-Handling Even Numbers: All even numbers greater than 2 are not prime,
so you can add an early check for divisibility by 2 to further optimize the
code. For example:
if n==2:
return True
if n%2 == 0 :
return False

-Loop Limit Optimization: Instead of checking divisibility up to n-1, you
can check up to the square root of n.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Reason about the importance of normalization in logical data modeling. What
could be the consequences of not normalizing a database?

A
  • Normalization in logical data modeling is important because it organizes
    data efficiently, reducing redundancy and ensuring that data is stored
    consistently.
  • Consequences:
  • Data Duplication: The same information could be stored in multiple
    places, wasting storage space.
  • Update Anomalies: Changes in one part of the database might not
    automatically update in other places, leading to inconsistent data.
  • Insertion Problems: Adding new data can be tricky without having
    all the necessary related information already available
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Explain why Python uses indentation for defining blocks of code (like loops
and functions). What are the benefits and potential pitfalls of this approach?

A
  • Python uses indentation to define blocks of code (like loops and functions)
    because it enforces code readability and ensures consistent structure in
    writing programs.
  • Benefits:
  • Improved Readability: Indentation makes it easy to visually
    distinguish blocks of code, making it easier to understand.
  • Cleaner Syntax: No need for extra symbols like braces {} to define
    code blocks, keeping the code less cluttered.
  • Encourages Good Coding Habits: By requiring clean code, it
    promotes best practices early on.
  • Potential Pitfalls:
  • Indention Errors: Even small mistakes in indentation (like mixing
    spaces and tabs) can lead to syntax errors or unexpected behavior.
  • Harder to Debug: If indentation is inconsistent, it can be tricky to
    spot where exactly the mistake is in larger programs.
  • Collaboration Issues: Developers working on the same codebase
    need to agree on indentation rules (e.g., tabs vs. spaces).
  • Code Copy-Pasting Issues: When copying code from different
    sources, indentation might not align properly, causing errors.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Write a Python function that accepts a number and returns the sum of digits in
a number without using recursion. The function must accept a minimum of 5
digits number, otherwise, it will return a message “Minimum Requirements does
not meet.”
Case 1:
Enter a number: 12345
Sum is: 15
Case 2:
Enter a number: 123
Sum is: Minimum Requirements does not meet.

A

def sum(number):
if len(str(number)) < 5:
return “Minimum Requirements does not meet.”

total = 0;

for digit in str(number):
total += int(digit)
return total

number = int(input(“Enter a number: “))
result = sum(number)
print(result)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Write a Python function to reverse a given number. The function must accept a
minimum of 5 digits number, otherwise, it will return a message “Minimum
Requirements does not meet.”
Case 1:
Enter numbers separated by spaces: 12345
Sum is: 54321
Case 2:
Enter a number: 123
Sum is: Minimum Requirements does not meet.

A

def reverse(number):
if len(str(number) < 5:
return “Minimum Requirements does not meet.”

reversed = str(number)[::-1]

return int(reversed)

number = int(input(“Enter numbers separated by spaces: “))

result = reverse(number)

print(result)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly