MAD Study Hub

Home / Past papers / MAD1 End Term / this paper

IIT M FOUNDATION DIPLOMA FN EXAM - 22 Dec 2024

MAD1 End Term32 questions100 marks23 MCQ · 7 MSQ · 2 SAFoundation / Diploma / forenoon
Elapsed 00:00
Q1MCQ2 marks
question figure
Text of the picture (copyable)
Consider the following models Library and Book corresponding to tables library and book in SQLite database.

```python
class Library(db.Model):
    id = db.Column(db.Integer(), primary_key = True)
    name = db.Column(db.String(), unique = True)

class Book(db.Model):
    id = db.Column(db.Integer(), primary_key = True)
    name = db.Column(db.String(), unique = True)
    library = db.Column(db.Integer(), unique = True, db.ForeignKey("section.id"))
```

Based on the model schemas, what relationship do the classes Library and Book share?
  1. Many-to-Many
  2. One-to-Many
  3. One-to-One
  4. The tables are not at all related
Q2MCQ2 marks
question figure
Text of the picture (copyable)
Consider the following python code snippet "app.py", the HTML files, "base.html" and "home.html" residing in "templates" folder.

app.py
```python
from flask import Flask, render_template
app = Flask(__name__)

@app.route('/')
def home():
    return render_template('home.html')

app.run(debug=True)
```

home.html
```html
{% extends "base.html" %}
{% block content %}
<h3>This is from home.html</h3>
{% endblock %}
```

base.html
```html
<!DOCTYPE html>
<html lang="en">
<head>
    <title>Document</title>
</head>
<body>
    <h3 style="color: blue;"> This is from base.html </h3>
    {% block content %}
    {% endblock %}
</body>
</html>
```

What will be the rendered output for base URL if flask app is running locally on
http://localhost:5000
  1. question figure
    text
    This is from home.html
  2. question figure
    text
    This is from base.html
    This is from home.html
  3. question figure
    text
    This is from home.html
    This is from base.html
  4. question figure
    text
    Error
Q3MCQ2 marks
question figure
Text of the picture (copyable)
Consider the following Python code snippet.

```python
from string import Template

sentence = Template("A $var1 fox $var2 over the $var3 dog")

output = sentence.safe_substitute(word_dict)

print(output)
```

Which of the following options correctly represent(s) the dictionary `word_dict`, such that the code does not throw any error when run in the terminal?
  1. question figure
    text
    ```python
    word_dict = {'var1': 'quick'}
    ```
  2. question figure
    text
    ```python
    word_dict = {'var1': 'quick', 'var2': 'jumps'}
    ```
  3. question figure
    text
    ```python
    word_dict = {'var1': 'quick', 'var2': 'jumps', 'var3': 'lazy'}
    ```
  4. question figure
    text
    All of these
Q4MCQ2 marks
Which of the following is a time series database?
  1. MongoDB
  2. InfluxDB
  3. MySQL
  4. PostgreSQL
Q5MCQ2 marks
Match the platforms given in column A with their correct features in column B. question figure Match the platforms given in column A with their correct features in column B.
Text of the picture (copyable)
| Column A | Column B |
|---|---|
| 1. Desktop | A. Data center storage |
| 2. Mobile | B. Keyboard |
| 3. Web-based | C. Single function |
| 4. Embedded | D. tilt |
  1. 1 - A, 2 - B, 3 - C, 4 - D
  2. 1 - D, 2 - A, 3 - B, 4 - C
  3. 1 - B, 2 - D, 3 - A, 4 - C
  4. 1 - A, 2 - C, 3 - D, 4 - B
Q6MCQ3 marks
question figure
Text of the picture (copyable)
Consider the following view function.

```python
from flask import Flask, request
app = Flask(__name__)

@app.route('/employee', methods=['GET', 'POST'])
def show_info():
    info = request.args
    details = {
        'Department': info['dept'],
        'ID': info['id'],
        'Role': info['role']
    }
    return details

app.run()
```

If this flask app is running locally on http://127.0.0.1:5000, which of the following URLs will be handled by the controller correctly?
  1. question figure
    text
    ```
    http://127.0.0.1:5000?dept=HR&id=101&role=manager
    ```
  2. question figure
    text
    http://127.0.0.1:5000/HR/101/manager
  3. question figure
    text
    ```
    http://127.0.0.1:5000/employee?dept=HR&id=1018&role=manager
    ```
  4. question figure
    text
    ```
    http://127.0.0.1:5000/employee/HR/101/manager
    ```
Q7MCQ3 marks
question figure
Text of the picture (copyable)
A certain internet connection is established such that its bandwidth reduces to half of its current value every hour. A user connects to this connection at 01:00 pm with the network speed of 4 Mbps, how much data (in GBs) will be consumed by the user by 04:00 p.m in the evening? [round off upto 2 decimal places](Assume that the user is using the entire bandwidth)
  1. 1.35
  2. 2.7
  3. 3.15
  4. 5.4
Q8MCQ3 marks
question figure
Text of the picture (copyable)
Consider the following function to be tested and test functions given in the Python code snippet below.

file.py

```python
def sample_function(x):
    var = []
    for i in range(x):
        var.append((i)**3)
    return var

def test_func1():
    assert 125 in sample_function(6)

def test_func2():
    assert 64 in sample_function(8)

def sample_test3():
    assert 125 in sample_function(5)
```

What will be the summary of the output for the command
`pytest file.py` on the terminal?
  1. question figure
    text
    ```
    =========== 1 failed, 2 passed in 0.06s ===========
    ```
  2. question figure
    text
    ```
    ========== 2 failed, 1 passed in 0.06s ==========
    ```
  3. question figure
    text
    ```
    ============================= 3 passed in 0.06s =============================
    ```
  4. question figure
    text
    ```
    ============================= 2 passed in 0.06s =============================
    ```
Q9MCQ3 marks
Consider the following HTML document. question figure Consider the following HTML document.
Text of the picture (copyable)
```html
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script>
        function makeBold(){
            //MISSING JS CODE
        }
    </script>
</head>
<body>
    Enter your name : <input type="text" id="txt1" name="txt1">
    <br>
    <input type="button" onclick="makeBold();" value="Click Me">
</body>
</html>
```
Replace the **MISSING JS CODE** part with the correct JS code that will change the text box content to bold?
  1. question figure
    text
    ```javascript
    t=document.getElementsByName("txt1").value;
    t.style.fontWeight="bold";
    ```
  2. question figure
    text
    ```javascript
    t=document.getElementById("txt1").value;
    t.style.fontWeight="bold";
    ```
  3. question figure
    text
    ```javascript
    t=document.getElementById("txt1");
    t.style.fontWeight="bold";
    ```
  4. question figure
    text
    ```javascript
    t=document.getElementById("txt1");
    t.style.fontWeight="bold";
    ```
Q10MCQ3 marks
Match the following terms with their correct descriptions: question figure Match the following terms with their correct descriptions:
Text of the picture (copyable)
| | |
| :--- | :--- |
| A. DOM Event | 1. The structure that represents the HTML document and allows interaction with it. |
| B. Attributes | 2. A method or action triggered by user interactions like clicks, typing, etc. |
| C. Document | 3. The individual elements or parts of a page, such as elements, attributes, or text. |
| D. Node | 4. The properties that define the characteristics of an HTML element, like `id`, `class`, etc. |
| E. DOM (Document Object Model) | 5. A programming interface for web documents that provides structured access to the document's elements. |
  1. A → 2, B → 4, C → 1, D → 3, E → 5
  2. A → 3, B → 4, C → 1, D → 2, E → 5
  3. A → 2, B → 4, C → 5, D → 3, E → 1
  4. A → 3, B → 4, C → 5, D → 2, E → 1
Q11MCQ3 marks
Which of the following is an example of an application using Attribute-Based Access Control (ABAC)?
  1. A system where users are granted access based on their job roles within anorganization.
  2. A cloud service that grants or restricts access to files based on attributes suchas user department, job title, or current location.
  3. A file-sharing system where the file owner decides who can access theirdocuments.
  4. A system that enforces access based on security classifications and clearancelevels.
Q12MCQ3 marks
question figure
Text of the picture (copyable)
Consider the following Table products in SQLite database created using model class Product and the python file main.py given below.

products:

| id | pro_name  | section    |
|:---|:----------|:-----------|
| 1  | Palm Oil  | food       |
| 2  | Butter    | food       |
| 3  | Pencil    | art        |
| 4  | Face wash | cosmetics  |
| 5  | Olive     | vegetables |

main.py

```python
from jinja2 import Template
templates = """
    {% if result %}
    <ol>
        {% for product in products %}
        <li>{{product.pro_name}}</li>
        <li>{{product.section}}</li>
        {% endfor %}
    </ol>
    {% endif %}
"""

products = Product.query.filter_by(section = 'food').all()

Templates = Template(templates)
result = Templates.render(products = products)
print(result)
```

What will be the output on the terminal?
  1. question figure
    text
    Palm Oil food
    Butter food
  2. question figure
    text
    ```html
    <ol>
        <li>Palm Oil food</li>
        <li>Butter food</li>
    </ol>
    ```
  3. question figure
    text
    Palm Oil
    food
    Butter
    food
  4. question figure
    text
    ```html
    <ol>
        <li>Palm Oil</li>
        <li>food</li>
        <li>Butter</li>
        <li>food</li>
    </ol>
    ```
Q13MCQ3 marks
question figure
Text of the picture (copyable)
Consider the following Python code snippet.

```python
from math import factorial

def prettify(func):
    def wrapper(num):
        try:
            return func(num)
        except:
            return "Please check your number!"
    return wrapper

@prettify
def fact(num):
    return factorial(num)

out = fact(5)
print(out)
```

What will the output if the above Python code is run on the terminal?
  1. question figure
    text
    -120
  2. question figure
    text
    120
  3. question figure
    text
    Please check your number!
  4. question figure
    text
    None of these.
Q14MCQ4.5 marks
question figure
Text of the picture (copyable)
Consider the following Python code snippet.
file.py

```python
from string import Template as makeTemplate
from jinja2 import Template
import sys

var = sys.argv[2]

data = {"name": "Alice", "activity": "data analysis",
        "tool": "Python", "goal": "insights"}

temp = "{{name}} performs $activity using $tool to gain {{goal}}."

if var == "python":
    temp = makeTemplate(temp)
    out = temp.substitute(data)
    output = Template(out)
    output = output.render(data)
    print(output)
else:
    temp = Template(temp)
    output = temp.render(data)
    print(output)
```

What will be printed on the terminal for the command `python file.py ml python`?
  1. question figure
    text
    Alice performs $activity using $tool to gain insights.
  2. question figure
    text
    ```
    {{name}} performs $activity using $tool to gain {{goal}}.
    ```
  3. question figure
    text
    Alice performs data analysis using Python to gain insights.
  4. question figure
    text
    ```
    Alice performs $activity using $tool to gain {{goal}}.
    ```
Q15MCQ4.5 marks
Consider the following HTML document. question figure Consider the following HTML document. How will the browser render above HTML file?
Text of the picture (copyable)
```html
<!DOCTYPE html>
<html lang="en">
<head>
    <title>Document</title>
    <style>
        p {
            background-color: yellow;
            color: red;
            display: inline-block;
        }
        #id {
            border: 2px solid purple;
            color:blue ;
        }
        .class1 {
            background-color: aqua;
            color: red;
        }
        .class2{
            background-color: lightgreen;
            color: darkgreen;
        }
    </style>
</head>
<body>
    <p class="class1" id="id">Code 1</p>
    <p class="class1 class2" >Code 2</p>
    <p class="class1">Code 3</p>
    <p >Code 4</p>
</body>
</html>
```
  1. question figure
    text
    This is a diagram showing four stacked rectangular blocks, each with text.
    The top block is light blue with a purple border and contains the text "Code 1" in blue.
    The second block is light green and contains the text "Code 2" in green.
    The third block is light blue and contains the text "Code 3" in brown.
    The bottom block is yellow and contains the text "Code 4" in orange.
  2. question figure
    text
    This is a diagram showing four colored horizontal bars, each with text.
    
    - Top bar (cyan with a purple border): Code 1
    - Second bar (cyan): Code 2
    - Third bar (light green): Code 3
    - Bottom bar (yellow): Code 4
  3. question figure
    text
    Code 1 Code 2 Code 3 Code 4
  4. question figure
    text
    The image displays four rectangular boxes arranged horizontally.
    1. The first box has a purple border and a light blue fill. Inside, the text "Code 1" is written in blue.
    2. The second box has a light green fill. Inside, the text "Code 2" is written in green.
    3. The third box has a light blue fill. Inside, the text "Code 3" is written in red.
    4. The fourth box has a yellow fill. Inside, the text "Code 4" is written in red.
Q16MCQ4.5 marks
question figure
Text of the picture (copyable)
Refer to the project with three files: `conftest1.py`, `test_multiples_of_3_and_6.py`, and `test_multiples_of_13.py`.

The purpose of the tests is to verify if numbers generated by each function are divisible by 39. However, there is a setup issue in this project.

* `conftest1.py` contains a fixture that provides test data.
* `test_multiples_of_3_and_6.py` has two functions: one checks divisibility by 3, and the other by 6.
* `test_multiples_of_13.py` contains a function to check divisibility by 13.

Here is the content of each file:

**conftest1.py**
```python
import pytest

@pytest.fixture
def divisible_by_39():
    return 39 # Fixture providing the number to be tested
```

**test_multiples_of_3_and_6.py**
```python
import pytest

def test_divisible_by_3(divisible_by_39):
    assert divisible_by_39 % 3 == 0 # Checks if divisible by 3

def test_divisible_by_6(divisible_by_39):
    assert divisible_by_39 % 6 == 0 # Checks if divisible by 6
```

**test_multiples_of_13.py**
```python
import pytest

def test_divisible_by_13(divisible_by_39):
    assert divisible_by_39 % 13 == 0 # Checks if divisible by 13
```

When you run `pytest -k divisible`, which of the following is **true**?
  1. question figure
    text
    ```
    ========== 1 passed in 0.02s ==========
    ```
  2. question figure
    text
    ```
    ========== 3 passed in 0.02s ==========
    ```
  3. question figure
    text
    ```
    ========= 1 failed, 2 passed in 0.06s =========
    ```
  4. question figure
    text
    ```
    ========== 3 errors in 0.02s ==========
    ```
Q17MCQ4.5 marks
question figure
Text of the picture (copyable)
Consider the following Python code snippet that returns the potential energy stored in an object of a certain mass at a certain height. (PE = mgh, where "g" is acceleration due to gravity).

```python
from jinja2 import Template

x = Template(template)
```

What should be the value of template if;
`print(x.render(mass = "5", height = "22"))` returns 1100 and
`print(x.render())` returns 3000
  1. question figure
    text
    ```
    "{{ mass|default(3)|int*gravity|default(10)|int*height|default(100)|int }}"
    ```
  2. question figure
    text
    ```
    "{{ mass|int|default(3)*gravity|int|default(10)*height|int|default(100) }}"
    ```
  3. question figure
    text
    ```
    "{{ mass|default(5)|int*gravity|default(10)|int*height|default(100)|int }}"
    ```
  4. question figure
    text
    ```
    "{{ mass|int|default(5)*gravity|int|default(10)*height|int|default(100) }}"
    ```
Q18MSQ4.5 marksselect all that apply
question figure
Text of the picture (copyable)
Consider the following flask app. Given that `test_request_context()` allows text to be printed on the terminal, which of the following statements is/are correct?

```python
from flask import Flask, url_for
app = Flask(__name__)

@app.route('/products')
def products():
    return 'Product List'

@app.route('/product/<int:product_id>/<string:name>')
def product_detail(product_id, name):
    return f'Product ID: {product_id}, Name: {name}'

with app.test_request_context():
    #== print statement ==#
```
  1. question figure
    text
    If `print statement` is replaced by:
    ```python
    print(url_for('products', category="electronics"))
    ```
    the output on the terminal will be;
    `/products?category=electronics`
  2. question figure
    text
    If #== *print statement* ==# is replaced by:
    ```python
    print(url_for('products', category="electronics")),
    ```
    the output on the terminal will be;
    /products/electronics
  3. question figure
    text
    If #== print statement ==# is replaced by:
    ```python
    print(url_for('product_detail', product_id=101, name="Gadget", discount=20))
    ```
    the output on the terminal will be;
    /product/101/Gadget?discount=20
  4. question figure
    text
    If #== print statement ==# is replaced by:
    ```python
    print(url_for('product_detail', product_id=101, name="Gadget", discount=20))
    ```
    the output on the terminal will be;
    /product/101/Gadget/20
Q19MSQ3 marksselect all that apply
Consider the following code snippet. question figure Consider the following code snippet.
Text of the picture (copyable)
```python
from flask import Flask
import logging
app = Flask(__name__)

logging.basicConfig(filename='logger.log', level=logging.INFO,
                    format=f'%(asctime)s : %(message)s')

@app.route('/home')
def home():
    app.logger.debug('This is a debug log')
    app.logger.warning('This is a warning log')
    return f"Application Dashboard"

if __name__ == "__main__":
    app.run()
```
Suppose the given flask application is running locally on http://127.0.0.1:5000, which of the following statements is/are true if you hit the URL http://127.0.0.1:5000/home ?
  1. question figure
    text
    A file called "logger.log" will be created inside the Flask application root folder.
  2. question figure
    text
    The message "Application Dashboard" will be displayed within the log file.
  3. question figure
    text
    The message "This is a debug log" will be logged inside the "logger.log" file.
  4. question figure
    text
    The message "This is a warning log" will be logged inside the "logger.log" file.
Q20MSQ3 marksselect all that apply
Consider the following flask application running on the base URL and is accessed through a browser. Select the correct option(s). question figure Consider the following flask application running on the base URL and is accessed through a browser. Select the correct option(s).
Text of the picture (copyable)
```python
app = Flask(__name__)

users = {
    1 : {"Name": "Mukesh", "role": "Admin", "access": True},
    2 : {"Name": "Gautam", "role": "User", "access": True},
    3 : {"Name": "Narendra", "role": "Admin", "access": True},
    4 : {"Name": "Amit", "role": "User", "access": False}
}

@app.route('/login')
def auth():
    cred = request.args
    if users[int(cred["id"])].get("access"):
        id = int(cred["id"])
        user = users[id]
        return "Welcome, "+ user.get("Name")+", you have "+user.get("role") \
            + " access"
    else:
        abort(403)

@app.errorhandler(403)
def no_access(error):
    return "You are an unauthorized user!"

app.run(debug = True)
```
  1. question figure
    text
    For the URL: http://127.0.0.1:5000?id=2, The browser will render;
    Welcome, Gautam, you have User access.
  2. question figure
    text
    For the URL: http://127.0.0.1:5000/login?id=1, The browser will render;
    Welcome, Mukesh, you have Admin access.
  3. question figure
    text
    For the URL: http://127.0.0.1:5000/login?id=3, The browser will render,
    Welcome, Narendra, you have User access.
  4. question figure
    text
    For the URL: http://127.0.0.1:5000/login?id=4, The browser will render,
    You are an unauthorized user!
Q21MSQ3 marksselect all that apply
Consider the following Python code snippet. question figure Consider the following Python code snippet.
Text of the picture (copyable)
File name: main.py
```python
import sys

def func1(x):
    return x > 0

def func2(x):
    return x % 2 == 0

def test_fun3(x):
    assert func1(x) == True, str(x) + " is not even/odd"
    assert func2(x) == True, str(x) + " is even number"
    assert x % 2 != 0, str(x) + " is odd number"

x = int(sys.argv[1])
test_fun3(x)
```

Which of the following is the correct combinations of “command line argument” and “assertion error”?
  1. question figure
    text
    Command: python main.py 9
    AssertionError: 9 is even number
  2. question figure
    text
    Command: python main.py 90
    AssertionError: 90 is odd number
  3. question figure
    text
    ```
    Command: python main.py 0
    AssertionError: 0 is not even/odd
    ```
  4. question figure
    text
    Command: python main.py 9
    AssertionError: 9 is odd number
  5. question figure
    text
    Command: python main.py 90
    AssertionError: 90 is even number
Q22MSQ3 marksselect all that apply
Which of the following statements about the Constraint Validation API is/are true?
  1. The Constraint Validation API ensures that form input meets client-sidevalidation rules before submission.
  2. The Constraint Validation API is sufficient to prevent server-side attacks likeSQL injection.
  3. It is possible to bypass the Constraint Validation API by directly sendingrequests to the server.
  4. The Constraint Validation API automatically validates all data on the serverside.
Q23MSQ2 marksselect all that apply
Which of the following statements is invalid in the context of the primary key?
  1. The primary key can be null
  2. The primary key can be auto-incremented
  3. The primary key allows duplicate values
  4. The primary key can be referenced by foreign keys in other tables.
Q24MSQ2 marksselect all that apply
Consider the following HTML document. question figure Consider the following HTML document. Which of the following statements is/are correct about the above code snippet?
Text of the picture (copyable)
```html
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>IITM</title>
</head>
<body>
    <h2>Welcome to IITM </h2>
    <h3>Online Degree</h3>
    Courses offered
    <ol>
        <li>Foundation</li>
        <ul>
            <li>CT</li>
            <li>Python</li>
            <li>Maths-I</li>
        </ul>
        <li>Diploma</li>
        <ul>
            <li>PDSA</li>
            <li>MAD-I</li>
            <li>MAD-II</li>
        </ul>
    </ol>
</body>
</html>
```
  1. List Items, Foundations and Diploma are numbered 1 and 2
  2. List Items, Foundations and Diploma are bulleted
  3. List Items, PDSA, MAD-I and MAD-II are numbered 1, 2 and 3
  4. List Items, PDSA, MAD-I and MAD-II are bulleted
Q25SA3 marks
question figure
Text of the picture (copyable)
Consider a comma-separated values (CSV) file with all characters set ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b"]. You need to store a file consisting of 2000 characters mentioned only in the above list without spaces. How many minimum number of bytes are required to store this CSV file efficiently?
Q26SA3 marks
question figure
Text of the picture (copyable)
You are connected to a server that can process 1500 requests per second. Each request is a constant size of 100KB. You are connected to the above server through a network line with a speed of 2Gbps. What is the maximum number of requests per second that the server can handle(in KBps)? (Consider that 1000Bytes=1KB, 1000KB = 1MB)?
Comprehension passage - the questions below it refer to this
Based on the above data, answer the given subquestions. question figure
Q27MCQ3 marks
question figure
Text of the picture (copyable)
Which of the following urls will display [Joker]
on the browser?
  1. question figure
    text
    http://127.0.0.1:5000/action
  2. question figure
    text
    http://127.0.0.1:5000/thriller
  3. question figure
    text
    http://127.0.0.1:5000/comedy
  4. question figure
    text
    http://127.0.0.1:5000?genre=thriller
Q28MCQ2 marks
question figure
Text of the picture (copyable)
What will be displayed on the browser for the url:
http://127.0.0.1:5000?genre=action ?
  1. question figure
    text
    [5, 3]
  2. question figure
    text
    ```
    ["Spider man 1", "Batman"]
    ```
  3. question figure
    text
    ```
    ["Sam Raimi", "Matt Reeves"]
    ```
  4. question figure
    text
    None of these.
Comprehension passage - the questions below it refer to this
question figure
Q29MCQ4.5 marks
question figure
Text of the picture (copyable)
What will be the output of the below terminal request?
```
curl http://127.0.0.1:5000/api/get_account/fd101 -X GET
```
  1. question figure
    text
    ```json
    {
        "name": "Jack",
        "balance": 71600
    }
    ```
  2. question figure
    text
    Sorry, account no. fd101 does not exist
  3. question figure
    text
    Account no. fd101 does not exist and balance not updated...
  4. question figure
    text
    ```json
    {
        "name": "Syam",
        "balance": 9600
    }
    ```
Q30MCQ4.5 marks
question figure
Text of the picture (copyable)
Which of the following command will
update balance of account no. **ca101**?
  1. question figure
    text
    ```
    curl http://127.0.0.1:5000/api/update_balance/ca101 -X POST -d
    "{\"balance\":\"15890\"}" -H "Content-Type: application/json"
    ```
  2. question figure
    text
    ```
    curl http://127.0.0.1:5000/api/get_balance/ca101 -X POST -d
    "{\"balance\":\"15890\"}" -H "Content-Type: application/json"
    ```
  3. question figure
    text
    ```
    curl http://127.0.0.1:5000/api/get_balance/ca101 -X PUT -d
    "{\"balance\":\"15890\"}" -H "Content-Type: application/json"
    ```
  4. question figure
    text
    ```
    curl http://127.0.0.1:5000/api/update_balance/ca101 -X PUT -d
    "{\"balance\":\"15890\"}" -H "Content-Type: application/json"
    ```
Comprehension passage - the questions below it refer to this
Use the Python code given below for answering the subquestions: question figure Use the Python code given below for answering the subquestions:
Q31MCQ4.5 marks
question figure
Text of the picture (copyable)
Assume you have the following Item
API endpoint as shown in the code. If
a client sends a POST request with an
existing item name but missing the
price field in the JSON payload,
what will happen, and why?
  1. question figure
    text
    The server will add a new item with **None**
    as the price value and return a 201
    status code since there is no
    validation for the price field.
  2. question figure
    text
    The server will raise a KeyError because
    it tries to access data['price'] without
    validating if price is present, returning a 500
    Internal Server Error.
  3. question figure
    text
    The server will return a 400 status code
    with the message "Item already exists"
    because it first checks for the item's
    existence before attempting to access price.
  4. question figure
    text
    The server will reject the request and
    return a 404 status code, indicating
    a missing field, because price
    is required.
Q32MCQ3 marks
question figure
Text of the picture (copyable)
What will be the status code of the response
for the request:

```
curl http://127.0.0.1:5000/item/candle?price=120 -X POST
```
  1. 201
  2. 404
  3. 500
  4. None of these

Answer key

  1. Q1 (MCQ, 2 marks): D
  2. Q2 (MCQ, 2 marks): B
  3. Q3 (MCQ, 2 marks): D
  4. Q4 (MCQ, 2 marks): B
  5. Q5 (MCQ, 2 marks): C
  6. Q6 (MCQ, 3 marks): C
  7. Q7 (MCQ, 3 marks): C
  8. Q8 (MCQ, 3 marks): D
  9. Q9 (MCQ, 3 marks): D
  10. Q10 (MCQ, 3 marks): A
  11. Q11 (MCQ, 3 marks): B
  12. Q12 (MCQ, 3 marks): D
  13. Q13 (MCQ, 3 marks): B
  14. Q14 (MCQ, 4.5 marks): C
  15. Q15 (MCQ, 4.5 marks): D
  16. Q16 (MCQ, 4.5 marks): D
  17. Q17 (MCQ, 4.5 marks): A
  18. Q18 (MSQ, 4.5 marks): A, C
  19. Q19 (MSQ, 3 marks): A, D
  20. Q20 (MSQ, 3 marks): B, D
  21. Q21 (MSQ, 3 marks): A, B, C
  22. Q22 (MSQ, 3 marks): A, C
  23. Q23 (MSQ, 2 marks): A, C
  24. Q24 (MSQ, 2 marks): A, D
  25. Q25 (SA, 3 marks): 1000
  26. Q26 (SA, 3 marks): 150000
  27. Q27 (MCQ, 3 marks): C
  28. Q28 (MCQ, 2 marks): B
  29. Q29 (MCQ, 4.5 marks): A
  30. Q30 (MCQ, 4.5 marks): D
  31. Q31 (MCQ, 4.5 marks): B
  32. Q32 (MCQ, 3 marks): D

Concepts this paper tests

Auto-generated summary from the source site. Handy as a checklist; the lessons above explain each idea from scratch.

Here’s a structured summary of the core topics, concepts, and principles essential for the Diploma Level: Modern Application Development I exam, along with a knowledge graph in Mermaid syntax.


Core Topics and Concepts Summary

1. Web Development with Flask

Key Concepts:

Key Code Snippets:

### Basic Flask App
from flask import Flask
app = Flask(__name__)
@app.route('/')
def home():
    return "Hello, World!"
app.run(debug=True)

### Dynamic Routing
@app.route('/user/<username>')
def show_user(username):
    return f"User: {username}"

### Query Parameters
from flask import request
@app.route('/search')
def search():
    query = request.args.get('q')
    return f"Search query: {query}"

### Jinja2 Template Rendering
from flask import render_template
@app.route('/template')
def template():
    return render_template('index.html', title="Home")

### REST API with Flask-RESTful
from flask_restful import Api, Resource
api = Api(app)
class HelloWorld(Resource):
    def get(self):
        return {"message": "Hello, World!"}
api.add_resource(HelloWorld, '/api/hello')

2. Databases and SQLAlchemy

Key Concepts:

Key Code Snippets:

### SQLAlchemy One-to-Many Relationship
class Library(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    books = db.relationship('Book', backref='library')

class Book(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    library_id = db.Column(db.Integer, db.ForeignKey('library.id'))

### Querying with SQLAlchemy
books = Book.query.filter_by(library_id=1).all()

3. Frontend Development (HTML/CSS/JS)

Key Concepts:

Key Code Snippets:

<!-- HTML Lists -->
<ol>
  <li>Item 1
    <ul>
      <li>Subitem 1</li>
    </ul>
  </li>
</ol>

<!-- CSS Specificity -->
<style>
  #id { color: red; }          /* Higher specificity */
  .class { color: blue; }      /* Lower specificity */
</style>

<!-- JavaScript DOM Manipulation -->
<script>
  document.getElementById("myInput").style.fontWeight = "bold";
</script>

4. Testing and Debugging

Key Concepts:

Key Code Snippets:

### Pytest Example
def test_addition():
    assert 1 + 1 == 2

### Flask Test Context
with app.test_request_context('/user?name=John'):
    print(request.args['name'])  # Output: John

### Custom Error Handling
from werkzeug.exceptions import HTTPException
class MyError(HTTPException):
    def __init__(self, message):
        super().__init__(message, 400)

5. Data Structures and Algorithms

Key Concepts:

Key Code Snippets:

### Decorator Example
def prettify(func):
    def wrapper(*args, **kwargs):
        try:
            return func(*args, **kwargs)
        except:
            return "Error occurred!"
    return wrapper

@prettify
def divide(a, b):
    return a / b

6. Access Control Models

Key Concepts:


7. Networking and Bandwidth

Key Concepts:

Equations:


8. REST APIs and HTTP Methods

Key Concepts:

Key Code Snippets:

### Flask-RESTful PUT Request
class Item(Resource):
    def put(self, id):
        data = request.get_json()
        items[id] = data
        return items[id], 201

Graph 1: Flask and Web Development

Graph 2: Databases and SQLAlchemy

Graph 3: Frontend Development

Graph 4: Testing and Debugging

Graph 5: Data and Networking