npressfetimg-41.png

Securities and Exchange Commission of Pakistan (SECP) to hold, Second ‘IICM Conference, Expo in Karachi

News

Second ‘International Islamic Capital Market’ Conference Details Unveiled

  • The Securities and Exchange Commission of Pakistan (SECP) unveiled the details of the Second ‘International Islamic Capital Market’ Conference, 2024 during a press briefing held on Wednesday at the SECP Karachi office.

  • Tariq Naseem, Head of Islamic Finance, highlighted:

    • Shariah-compliant segments now constitute a major portion of capital markets with 55% market capitalization of listed securities, 48% assets of mutual funds, 65% assets of voluntary pension funds, and 95% REITs.

    • The level of compliance of Pakistan’s capital market with IOSCO principles for securities regulation was assessed at 86% in an independent international assessment conducted in 2 Written as part of the course “Introduction to Programming”, this assignment introduces you to basic programming concepts that will be essential as we explore more complex topics in future courses.

Assignment Instructions:

Write a program that accomplishes each task below, which are designed to help solidify your understanding of key concepts and syntax from this course’s materials.

  1. Write a function called is_odd(n). This function should return True if the number n is odd, else False. In other words:
    • Given an integer input n, your program will evaluate whether it’s odd or not.
  2. Write another function called count_odds(l). The purpose of this function is to take in a list of integers and output the total number of odd numbers within that list. This will help you learn how to perform iteration over lists with loops (for loop), using your knowledge on basic Python syntax and functions, including calling/invoking other functions.
  3. Write another function called count_odds2(l). The purpose of this function is the same as count_odds(l), but it will use a list comprehension instead to get the total number of odd numbers in that list. This assignment task helps you learn how to write list comprehensions and practice using functions with list objects.
  4. Write one final program called run_all(). When given an input (integer or list of integers, whicheeer), this function should call all three above mentioned functions: is_odd(n), count_odds(l), count_odds2(l). The output should be a dictionary that contains results from calling each function. For example, if run_all() gets called with an integer argument, its result will be: { “is_odd”: True/False, “count_odds”: number of odds in the list [1,3,5]}.
    • This assignment task helps you learn how to call functions and how to handle different data types (int or list). It also encourages you to write more complex programs by combining multiple smaller functions together.

      To accomplish each task outlined in your assignment, let’s begin with the implementation of the basic functions and then proceed to the final program that combines these functionalities. We will work within a Python environment for this exercise.

Step 1: Implementing is_odd(n)

This function checks if an integer n is odd or even by utilizing the modulo operator (%). If n % 2 equals 1, then n is odd; otherwise, it’s even.

def is_odd(n):
    """Return True if n is odd, False otherwise."""
    return n % 2 == 1

Step 2: Implementing count_odds(l)

This function iterates over a list l of integers and counts how many are odd. It uses the previously defined is_odd function to determine if each element is odd.

def count_odds(l):
    """Return the total number of odd numbers in the list l."""
    return sum(1 for n in l if is_odd(n))

Step 3: Implementing count_odds2(l)

Using a list comprehension, this function does exactly what count_odds does but leverages Python’s concise syntax to achieve the same result more succinctly.

def count_odds2(l):
    """Return the total number of odd numbers in the list l using a list comprehension."""
    return sum(1 for n in l if is_odd(n))

Step 4: Implementing run_all()

The final program, run_all(), will take an input (either an integer or a list of integers) and call the three functions defined above. It then returns a dictionary containing the results from each function. To handle both inputs, we’ll check if the input is a single integer (n) or a list (l), and act accordingly.

def run_all(input):
    """Call all three previous functions with given input (integer or list) and return their results in a dictionary."""
    result = {}
if isinstance(input, int):
    # If the input is an integer
    result["is_odd"] = is_odd(input)
    result["count_odds"] = count_odds([input])  # Calling with a list containing only one item for consistency in counting odds.
elif isinstance(input, list):
    # If the input is a list of integers
    result["is_odd"] = False  # Assume False as we're checking all items, not individual numbers.
    result["count_odds"] = count Written as part of the course "Introduction to Programming", this assignment introduces you to basic programming concepts that will be essential as we explore more complex topics in future courses.

Assignment Instructions:

Write a program that accomplishes each task below, which are designed to help solidify your understanding of key concepts and syntax from this course's materials.

  1. Write a function called is_odd(n). This function should return True if the number n is odd, else False. In other words:
    • Given an integer input n, your program will evaluate whether it's odd or not.
  2. Write another function called count_odds(l). The purpose of this function is to take in a list of integers and output the total number of odd numbers within that list. This will help you learn how to perform iteration over lists with loops (for loop), using your knowledge on basic Python syntax and functions, including calling/invoking other functions.
  3. Write another function called count_odds2(l). The purpose of this function is the same as count_odds(l), but it uses a list comprehension to achieve this task. This introduces you to an alternative approach using Python's concise syntax for creating lists based on existing ones.
  4. Implement run_all(input), which takes either an integer or a list of integers as input and calls all three functions (is_odd, count_odds, and count_odds2). The output should be a dictionary that contains the results from each function call, formatted as shown:
    
     { "is_odd": True/False, 
       "count_odds": <number of odds>, 
       "count_odds2": &lt;number of odds&gt; }</code></pre>
    <p>This task helps you learn how to call functions with different data types and combine multiple functionalities into a single program. It also encourages you to handle input flexibility, ensuring your code can adapt to both integers and lists efficiently.</p>
    <h4>Python Implementation:</h4>
    <pre><code class="language-python">def is_odd(n):
     """Return True if n is odd, False otherwise."""
     return n % 2 == 1

def count_odds(l):
"""Return the total number of odd numbers in the list l."""
return sum(1 for n in l if is_odd(n))

def count_odds2(l):
"""Return the total number of odd numbers in the list l using a list comprehension."""
return sum(1 for n in l if n % 2 == 1)

def run_all(input):
"""Call all three functions with given input and return their results as a dictionary."""
result = {}

if isinstance(input, int):
    result["is_odd"] = is_odd(input)
    # For count_odds, we pass the list containing only the single integer.
    result["count_odds"] = count_odds([input])
elif isinstance(input, list):
    # We assume False for "is_odd" since it's not clear if we want to check each item individually or just get a total count.
    result["is_odd"] = False  # Placeholder value; can be adjusted based on the actual requirement.
    result["count_odds"] = count_odds(input)
    result["count_odds2"] = count_odds2(input)

return result</code></pre>

This program demonstrates how to handle different types of input and utilize basic programming concepts like functions, loops (for loop), conditional statements (if), and list comprehensions. It also showcases the flexibility in calling multiple functions within a single higher-order function (run_all).

Leave a Reply

Your email address will not be published. Required fields are marked *