MAD Study Hub

Home / Past papers / MAD1 End Term / this paper

IIT M FOUNDATION DIPLOMA FN EXAM QDF2 28 Apr 2024 - 28 Apr 2024

MAD1 End Term32 questions100 marks26 MCQ · 6 MSQFoundation / Diploma / forenoon / QDF2
Elapsed 00:00
Q1MCQ3 marks
question figure
Text of the picture (copyable)
Consider the following Python code snippet.

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

var = sys.argv[0]

data = {"var1": "Data scientist", "var2": "programming",
        "var3": "statistical", "var4": "insights"}

temp = "{{var1}} creates $var2 code with $var3 knowledge to create\
{{var4}}."

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

What will be printed on the terminal for the command `python app.py 1 2`?
  1. question figure
    text
    ```
    {{var1}} creates programming code with statistical knowledge to create {{var4}}.
    ```
  2. question figure
    text
    Data scientist creates $var2 code with $var3 knowledge to create insights.
  3. question figure
    text
    ```
    {{var1}} creates $var2 code with $var3 knowledge to create {{var4}}
    ```
  4. question figure
    text
    Data scientist creates programming code with statistical knowledge to create insights.
Q2MCQ2 marks
question figure
Text of the picture (copyable)
Consider the following flask application running locally on http://127.0.0.1:5000 ?

```python
from flask import Flask

app = Flask(__name__)

@app.route('/home/<string:url>')
def get_url_str(url):
    return "string "+url

@app.route('/home/<path:url>')
def get_url_pth(url):
    return "path "+url

app.run(debug = True)
```

Which of the following URLs will throw a 404 Not Found error?
  1. question figure
    text
    http://127.0.0.1:5000/home/modules
  2. question figure
    text
    http://127.0.0.1:5000/home/modules/chapters/one
  3. question figure
    text
    ```
    http://127.0.0.1:5000/home/library/modules/chapters/one
    ```
  4. question figure
    text
    None
Q3MCQ2 marks
question figure
Text of the picture (copyable)
Consider the following view function.

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

@app.route('/student', methods = ['GET', 'POST'])
def show_details():
    cred = request.args
    details = {
        'Stream': cred['dept'],
        'Roll': cred['roll'],
        'Course': cred['course']
    }
    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:50000?dept=data_science&roll=cs10018&course=cs2003
    ```
  2. question figure
    text
    http://127.0.0.1:5000/data_science/cs1001/cs2003
  3. question figure
    text
    http://127.0.0.1:5000/student?dept=data_science&roll=cs1001&course=cs2003
  4. question figure
    text
    http://127.0.0.1:5000/student/data_science/cs1001/cs2003
Q4MCQ2 marks
Which of the following is true about the term “stateless” in the client-server model?
  1. The server responds to the client based on the previous state.
  2. The server uses FTP protocol to respond to the client's request.
  3. Server use the URL to convey information to the client.
  4. Server is not required to maintain any state of client or session duringtransactions between client and server.
Q5MCQ2 marks
question figure
Text of the picture (copyable)
Consider the following snippet of HTML and its output rendered on the browser:
post
index.html

```html
<form action="/" method="POST">
    <label for="fname">What is your first name?</label><br>
    <input type="text" name="fname" id="fname"><br>
    <input type="submit" value="Submit">
</form>
```

Diagram: Browser window showing a web page.
The browser window has a dark grey title bar with "Form" as the tab title, a close button, a plus button, a dropdown arrow, a purple infinity symbol with "Private browsing", minimize, maximize, and close buttons.
Below the title bar is a navigation bar with back, forward, reload, home, shield, padlock, "localhost:5000", star, L, and menu icons.
The main content area of the browser window is white and displays:
"What is your firstname?"
Below this text is an empty rectangular input field.
Below the input field is a button labeled "Submit".

Which HTTP request would be sent to the server if the user enters "Mahesh" into the text box and clicks submit?
  1. GET
  2. POST
  3. PUT
  4. DELETE
Q6MCQ2 marks
Which of the below JavaScript statement(s) are used to print information on the browser’s console?
  1. window.alert()
  2. console.log()
  3. document.write()
  4. None of these
Q7MCQ2 marks
Which command of the below command creates a new branch in GIT?
  1. question figure
    text
    ```
    git new-branch <branch_name>
    ```
  2. question figure
    text
    ```
    git branch <branch_name>
    ```
  3. question figure
    text
    ```
    git new <branch_name>
    ```
  4. question figure
    text
    ```
    git create-branch <branch_name>
    ```
Q8MCQ2 marks
Consider the following statements and select the correct option: Statement 1: In a database, an index can only be created on one column of a table. Statement 2: Indexes cannot be created on columns which have duplicate values.
  1. Statement 1 is true & statement 2 is false
  2. Statement 2 is true & statement 1 is false
  3. Both statements 1 and 2 are true
  4. Both statements 1 and 2 are false
Q9MCQ3 marks
question figure
Text of the picture (copyable)
In the code snippet given below, what should come in place of code 1 and code 2 such that one book can have multiple sections and the converse does not hold true?

```python
from sqlalchemy import ForeignKey
from sqlalchemy import Integer, Column
from sqlalchemy.orm import DeclarativeBase
from sqlalchemy.orm import relationship

class Base(DeclarativeBase):
    Pass

class Section(Base):
    __tablename__ = "section_table"
    id = Column(Integer, primary_key=True)
    # write your code 1 here

class Book(Base):
    __tablename__ = "book_table"
    id = Column(Integer, primary_key=True)
    # write your code 2 here
```
  1. question figure
    text
    ```python
    code 1: book_id=Column(Integer, ForeignKey("book_table.id"))
    code 2: books = relationship("Section")
    ```
  2. question figure
    text
    ```python
    code 1: books = relationship("Section")
    code 2: section_id=Column(Integer, ForeignKey("book_table.id"))
    ```
  3. question figure
    text
    ```python
    code 1: books = relationship("Book")
    code 2: section_id=Column(Integer, ForeignKey("section_table.id"))
    ```
  4. question figure
    text
    ```python
    code 1: book_id=Column(Integer, ForeignKey("book_table.id"))
    code 2: sections = relationship("Book")
    ```
Q10MCQ3 marks
question figure
Text of the picture (copyable)
Consider the following flask app and Jinja2 template.
app.py

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

@app.route('/')
def index():
    return render_template("index.html", data=['Harry', 'Karl', 'John', 'Jason', 'Ros'])

app.run()
```

index.html

```html
<!DOCTYPE html>
<html lang="en">
<head>
    <title>Macro</title>
</head>
<body>
    {% macro unordered_list(items)%}
    <ul>
        {% for item in items %}
        {% if item|length <= 4 %}
        <li>{{item}}</li>
        {% endif %}
        {% endfor %}
    </ul>
    {% endmacro %}
    {{ unordered_list(data) }}
</body>
</html>
```

If the flask app is running locally on http://127.0.0.1:5000. What will be the output on the browser for the base URL?
  1. question figure
    text
    - Harry
    - Karl
    - John
    - Jason
    - Ros
  2. question figure
    text
    - Karl
    - John
  3. question figure
    text
    - Harry
    - Jason
  4. question figure
    text
    * Karl
    * John
    * Ros
Q11MCQ3 marks
question figure
Text of the picture (copyable)
Match the following types of testing with their functionality.

| | |
|---|---|
| A. White Box Testing | 1. Beta Testing |
| B. User Acceptance testing | 2. One step beyond integration Testing |
| C. System testing | 3. Simulates actual user interaction, allows to script browser |
| D. System testing Automation | 4. Considers internal functioning of the system |

Which of the following is the correct matching?
  1. question figure
    text
    A → 1, B → 2, C → 3, D → 4
  2. question figure
    text
    A → 4, B → 3, C → 2, D → 1
  3. question figure
    text
    A -> 4, B -> 1, C -> 2, D -> 3
  4. question figure
    text
    A → 3, B → 2, C → 1, D → 4
Q12MCQ3 marks
question figure
Text of the picture (copyable)
Consider the following flask application.

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

@app.route('/')
def square():
    val = request.args

    if val['num'] == '':
        return "<h1>Enter a valid number</h1>"
    elif val['num'].isalpha()==True:
        return "<h1>Invalid number</h1>"
    else:
        out = (int(val['num'])) * (val['num'])
        return f'<h1>{out}</h1>'

if(__name__ == "__main__"):
    app.run(debug=True)
```

If this flask app is running locally on http://localhost:5000, what is the output for the URL
http://localhost:5000/?num=2 ?
  1. 4
  2. 22
  3. ValueError
  4. 2
Q13MCQ3 marks
question figure
Text of the picture (copyable)
Consider the following Python code snippet.
log.py

```python
import logging
import sys

logging.basicConfig(level=logging.WARNING,
                    format='%(asctime)s - %(levelname)s - %(message)s')

def check_val(value):
    if value < 0:
        raise ValueError("Invalid value: Please enter a positive value.")
    else:
        logging.info("Value added: %s", value)

try:
    input_value = int(sys.argv[1])
    check_val(input_value)
except ValueError as ve:
    logging.exception("Exception occurred: %s", str(ve))
```

What will be the output on the terminal for the command: `python log.py -34`?
  1. question figure
    text
    2023-08-14 21:01:05,684 - INFO - Value added: 34
  2. question figure
    text
    ```
    2023-08-14 21:01:05,684 - WARNING - Value added: 34
    ```
  3. question figure
    text
    Error: Exception occurred: Invalid value: Please enter a positive value.
  4. question figure
    text
    None.
Q14MCQ3 marks
You have a DRAM module with bus width of 64 bits, clock speed of 2 GHz, and operating in DDR (double-data-rate or two values per clock cycle) mode. What is the maximum bandwidth (in Giga-bytes per second) of data transfer achievable with this module?
  1. 16
  2. 8
  3. 32
  4. 128
Q15MCQ3 marks
question figure
Text of the picture (copyable)
Consider the following flask resource created using flask_restful.

```python
from flask import Flask, request
from flask_restful import Api, Resource, reqparse

app = Flask(__name__)
api = Api(app)

parser = reqparse.RequestParser()
parser.add_argument("val")

class RestApi(Resource):
    def post(self, val):
        arg1 = parser.parse_args()
        arg2 = request.args
        return {
            "Course_1": arg1["val"],
            "Course_2": arg2["val"],
            "Course_3": val
        }

api.add_resource(RestApi, "/api/courses/<val>")
app.run(debug = True)
```

If the application is running locally on http://127.0.0.1:5000, What will be the output on the terminal for the command:

```bash
curl http://127.0.0.1:5000/api/courses/DBMS?val=JAVA -d "{\"val\":\"PDSA\"}" -X POST -H "Content-Type: application/json"
```
  1. question figure
    text
    ```json
    {
      "Course_1": "JAVA",
      "Course_2": "PDSA",
      "Course_3": "DBMS"
    }
    ```
  2. question figure
    text
    ```json
    {
        "Course_1": "DBMS",
        "Course_2": "JAVA",
        "Course_3": "PDSA"
    }
    ```
  3. question figure
    text
    ```json
    {
        "Course_1": "PDSA",
        "Course_2": "JAVA",
        "Course_3": "DBMS"
    }
    ```
  4. question figure
    text
    ```json
    {
        "Course_1": "PDSA",
        "Course_2": "DBMS",
        "Course_3": "JAVA"
    }
    ```
Q16MCQ3 marks
question figure
Text of the picture (copyable)
What will be the output of the following Python code?

```python
from jinja2 import Template
my_statement = Template("The special series is:{% for n in
range(1,15)%} {{n/3}}" "{% endfor %}")
out = my_statement.render()
print(out)
```
  1. The special series is: 1 0 1 0 1 0 1 0 1 0 1 0 1 0
  2. The special series is: 1 2 0 1 2 0 1 2 0 1 2 0 1 2
  3. The special series is: 1.0 0.0 1.0 0.0 1.0 0.0 1.0 0.0 1.0 0.0 1.0 0.0 1.0 0.0
  4. The special series is: 0.33 0.67 1.0 1.33 1.67 2.0 2.33 2.67 3.0 3.33 3.67 4.0 4.334.67
Q17MCQ3 marks
question figure
Text of the picture (copyable)
Consider that there are two HTML files.
i) index.html - Home page of the application
ii) login.html - Login page of the application

Which of the following code will navigate the user between **index.html** and **login.html**, and vice versa?
  1. question figure
    text
    ```html
    <!-- index.html contains-->
    <a src="index.html">Signin</a>
    
    <!-- login.html contains ->
    <a src="login.html">Home</a>
    ```
  2. question figure
    text
    ```html
    <!-- index.html contains ->
    <a href="index.html">Signin</a>
    
    <!-- login.html contains ->
    <a href="login.html">Home</a>
    ```
  3. question figure
    text
    ```html
    <!-- index.html contains ->
    <a href="login.html">Signin</a>
    
    <!-- login.html contains ->
    <a href="index.html">Home</a>
    ```
  4. question figure
    text
    ```html
    <!-- index.html contains ->
    <a src="login.html">Signin</a>
    
    <!-- login.html contains ->
    <a src="index.html">Home</a>
    ```
Q18MCQ3 marks
question figure
Text of the picture (copyable)
Consider the below two data models Author and Book using SQLite database.

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

class Book(db.Model):
    id = db.Column(db.Integer(), primary_key=True)
    title = db.Column(db.String())
    publisher = db.Column(db.String())
    written_by = db.Column(db.Integer(), db.foreign_key("author.id"))
```

What kind of relationship exists between Author and Book classes?
  1. One Book to one Author relationship
  2. One Author to many Books relationship
  3. Many Authors to one Book relationship
  4. Many Books to many Author relationship
Q19MCQ4.5 marks
question figure
Text of the picture (copyable)
Consider a function func, and a set of test cases given below.
Filename: test_file.py

```python
import pytest

def func(x,y):
    out = x**2+y**2
    return out

class Test_class0():
    def test_case1(self):
        assert func(1,2) == 5

    def case_test2(self):
        assert func(2,3) == 13

    def test_case3(self):
        assert func(6,2) == 38

class Test_class1():
    def test_case1(self):
        assert func(5,2) == 29

    def case_test2(self):
        assert func(1,1) == 2
```

What will be the output on the terminal for the command below?
pytest test_file.py -k Test_class
  1. question figure
    text
    ```
    == 1 failed, 4 passed in 0.17s ===
    ```
  2. question figure
    text
    ```
    == 1 failed, 2 passed, 2 deselected in 0.17s ===
    ```
  3. question figure
    text
    ```
    == 2 failed, 1 deselected in 0.17s ===
    ```
  4. question figure
    text
    ```
    == 1 failed, 2 passed in 0.14s ===
    ```
Q20MCQ4.5 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 %}
<p>MAD I</p>
<span>MAD II</span>
<span>DBMS</span>
{% endblock %}
```

base.html
```html
<!DOCTYPE html>
<html lang="en">
<head>
    <title>IITM</title>
</head>
<body>
    <h2 style="color: violet;"> Diploma Courses </h2>
    {% 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
    MAD I
    MAD II
    DBMS
  2. question figure
    text
    Diploma Courses
    MAD I
    MAD II
    DBMS
  3. question figure
    text
    Diploma Courses
    
    MAD I
    
    MAD II DBMS
  4. question figure
    text
    MAD I
    
    MAD II DBMS
Q21MCQ4.5 marks
Consider the following graph that represents the variation in bandwidth of a network for an entire day (24 hours). Three users were connected to the network at three different times of the day. What is the total data consumed in GigaBytes by all the users in 24 hrs? question figure Consider the following graph that represents the variation in bandwidth of a network for an entire day (24 hours). Three users were connected to the network at three different times of the day. What is the total data consumed in GigaBytes by all the users in 24 hrs?
Text of the picture (copyable)
This is a 2D line graph with a horizontal axis labeled "Time (Hours)" ranging from 0 to 24, and a vertical axis labeled "BandWidth" with units "Megabits/s" ranging from 0 to 12.

There are three horizontal colored lines at the top of the graph, each labeled:
- A blue line labeled "user 1" extends from Time 0 to 4.
- A yellow line labeled "user 2" extends from Time 8 to 14.
- A green line labeled "user 3" extends from Time 14 to 24.

There is an orange step-function line representing bandwidth over time:
- From Time 0 to 4, BandWidth is 8 Megabits/s.
- From Time 4 to 8, BandWidth is 10 Megabits/s.
- From Time 8 to 12, BandWidth is 6 Megabits/s.
- From Time 12 to 16, BandWidth is 8 Megabits/s.
- From Time 16 to 20, BandWidth is 2 Megabits/s.
- From Time 20 to 24, BandWidth is 4 Megabits/s.

Vertical dashed lines extend from the horizontal axis at Time 4, 8, 12, 14, 16, 20, and 24, indicating the points where the bandwidth or user activity changes.
  1. 547.2 GB
  2. 12 GB
  3. 43.2 GB
  4. 345.6 GB
Q22MCQ4.5 marks
question figure
Text of the picture (copyable)
Consider the following restful implementation using flask.

```python
from flask import Flask, request
from flask_restful import Resource, Api

app = Flask(__name__)
api = Api(app)

student_info = {"name": "Ramesh", "Roll_No":"user123",
"Email":"ramesh.user@kmail.com"}

class Student(Resource):
    def delete(self):
        data = request.json
        student_info.update(data)
        return student_info

    def put(self):
        student_info.popitem()
        return "success", 200

api.add_resource(Student, '/')

app.run()
```

If the above application is running on http://127.0.0.1:5000 then what will be the final output on terminal on executing these two curl commands in the order mentioned?

1:

```bash
curl -X PUT -H "Content-Type: application/json" -H "Accept-Type: application/json" -d "{\"Roll_No\":\"user321\", \"Email\":\"r.user@kmail.com\"}" http://127.0.0.1:5000/
```

2:

```bash
curl -X DELETE -H "Content-Type: application/json" -H "Accept-Type: application/json" -d "{\"Roll_No\":\"user321\", \"Email\":\"r.user@kmail.com\"}" http://127.0.0.1:5000/
```
  1. question figure
    text
    ```json
    {
      "name": "Ramesh",
      "Roll_No": "user321",
      "Email": "r.user@kmail.com"
    }
    ```
  2. question figure
    text
    ```json
    {
        "name": "Ramesh",
        "Roll No": "user321"
    }
    ```
  3. question figure
    text
    ```json
    {
        "Roll No":"user321",
        "Email":"r.user@kmail.com"
    }
    ```
  4. question figure
    text
    ```json
    {
        "name": "Ramesh",
        "Roll_No": "user123",
        "Email": "r.user@kmail.com"
    }
    ```
Q23MCQ4.5 marks
question figure
Text of the picture (copyable)
An HTML code and CSS code is given below. Which of the following correctly represents
its rendered output?
CSS Code:

```css
#one{color: blue;}
.two{color: red !important;}
#two{color: green}
#three{color: green;}
```

HTML Code:

```html
<!DOCTYPE html>
<html>
<head>
    <title>Document</title>
    <link href="style.css" rel="stylesheet">
    <style>
        body{font-weight: bold;}
        p{color: violet !important ;}
    </style>
</head>
<body>
    <span id="one">Content 1</span>
    <span class="two" id="two">Content 2</span>
    <p id="three">Content 3</p>
</body>
</html>
```
  1. question figure
    text
    Content 1 Content 2
    Content 3
  2. question figure
    text
    Content 1
    Content 2
    Content 3
  3. question figure
    text
    Content 1 Content 2
    Content 3
  4. question figure
    text
    Content 1 Content 2
    Content 3
Q24MCQ4.5 marks
question figure
Text of the picture (copyable)
Consider the below two python files code snippets app.py and test_app_route.py.
app.py

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

@app.route("/greet/<string:name>")
def home(name):
    return "Hello, " + name

if __name__ == "__main__":
    app.run()
```

test_app_route.py:

```python
import pytest, requests

@pytest.fixture
def get_response():
    resp = requests.get("http://127.0.0.1:5000/greet/IITM")
    return resp

def test_response(get_response):
    assert get_response.text == "Hello, IITM"
```

Assume that app.py and test_app_route.py are running on two different terminals and all required modules are installed, then which of the following is the correct option for the statements given below?

i) Executing the command `pytest test_app_route.py` on the terminal returns
`=========== 1 passed ===========`

ii) Executing the command `pytest test_app_route.py` on the terminal returns
`=========== 1 failed ===========`

iii) Executing the command `pytest test_app_route.py` on the terminal returns
`=========== 1 selected, 1 passed ===========`

iv) Executing the command `pytest test_app_route.py` on the terminal returns
`=========== 1 deselected ===========`
  1. Statements i and iii are correct
  2. Statements ii and iv are correct
  3. Only statement i is correct
  4. Only statement ii is correct
Q25MSQ2 marksselect all that apply
question figure
Text of the picture (copyable)
What can be inferred from the Entity-Relationship Diagram below:

ER Diagram:
- Two entities: `Salary_Slip` and `Employee`.
- `Salary_Slip` entity has the following attributes:
  - `slip_id` (PK)
  - `Year` (DateTime)
  - `Month` (DateTime)
  - `Salary_issued` (Boolean)
  - `Total_salary` (Integer)
- `Employee` entity has the following attributes:
  - `Employee_id` (PK)
  - `Employee_name` (Text)
- A relationship exists between `Salary_Slip` and `Employee`.
- The relationship line connects `Salary_Slip` to `Employee`.
- The `Salary_Slip` side of the relationship has a crow's foot (many) and a single line (exactly one or more).
- The `Employee` side of the relationship has two vertical lines (exactly one).
- This indicates a many-to-one relationship where many `Salary_Slip` records can be associated with exactly one `Employee`.
  1. An employee can exist without having any salary slips
  2. An employee can have more than one salary slip
  3. An employee needs to have at least one salary slip
  4. A salary slip must belong to one and only one employee
Q26MSQ3 marksselect all that apply
question figure
Text of the picture (copyable)
Consider the following python code snippet.

```python
from string import Template

statement = "The $animal jumped over the $obstacle."

temp = Template(statement)

print(=== OUTPUT ===)
```

Which of the following statements, when substituted in place of === OUTPUT ===, will not throw a KeyError?
  1. question figure
    text
    ```python
    temp.substitute({"animal": "cat"})
    ```
  2. question figure
    text
    ```python
    temp.safe_substitute({"animal": "dog", "obstacle": "fence"})
    ```
  3. question figure
    text
    ```python
    temp.safe_substitute({"animal": "rabbit"})
    ```
  4. question figure
    text
    ```python
    temp.substitute({"animal": "horse", "obstacle": "wall"})
    ```
Q27MSQ3 marksselect all that apply
Which of the below is/are true about the Web Server?
  1. Always web server response in HTML format
  2. Web servers process the business logic and return different types of responses
  3. Web servers can host multiple web applications
  4. The web server sends the requested web page using HTTP
Q28MSQ3 marksselect all that apply
Consider a client ‘C’ and a server ‘S’, separated by distance ‘D’ are connected by a fictitious medium in which the speed of light is ‘v’ m/sec. If ‘N’ is the number of consecutive requests that can made in a second by the client ‘C’ (i.e A new request can be made only after receiving the response from the previous request.), Which of the following changes would halve the number ‘N’?
  1. A change of medium where the speed of light is 2v m/sec.
  2. Reduce the distance between C and S from D to D/2.
  3. A change of medium where the speed of light is v/2 m/sec.
  4. Increase the distance between C and S from D to 2D.
Q29MSQ4.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('/library')
def home():
    return 'Select your course!'

@app.route('/student/<username>/<roll>')
def dashboard(username):
    return f'{username}\'s dashboard'

with app.test_request_context():
    #== print statement ==#
```
  1. question figure
    text
    If `print statement` is replaced by:
    ```python
    print(url_for('home', user = "mad1_cs2003"))
    ```
    the output on the terminal will be;
    `/library/mad1_cs2003.`
  2. question figure
    text
    If `#== print statement ==#` is replaced by:
    ```python
    print(url_for('home', user = "mad1_cs2003")),
    ```
    the output on the terminal will be;
    `/library?user=mad1_cs2003.`
  3. question figure
    text
    If #== *print statement* ==# is replaced by:
    ```python
    print(url_for('dashboard', username = "mad1", roll = "cs2003", term = "jan2024"))
    ```
    the output on the terminal will be;
    `/student/mad1/cs2003?term=jan2024.`
  4. question figure
    text
    If #== *print statement* ==# is replaced by:
    ```python
    print(url_for('dashboard', username = "mad1", roll = "cs2003", term = "jan2024"))
    ```
    the output on the terminal will be:
    /student/mad1/cs2003/jan2024.
Q30MSQ4.5 marksselect all that apply
question figure
Text of the picture (copyable)
Consider the following function to be tested and test functions given in the Python code snippet below.

**test_file.py**
```python
import pytest

def square(x):
    sum = 0
    for counter in range(x):
        sum += x
    return sum

@pytest.mark.marker1
def testcase_1():
    assert square(10) == 100

@pytest.mark.marker2
def testcase_2():
    assert square(4) == 4

@pytest.mark.marker3
def testcase_3():
    assert square(5) == 25

@pytest.mark.marker4
def testcase_4():
    assert square(6) == 6
```

On running this file on the terminal using pytest, the summary of the output is:

`========= 1 failed, 3 deselected, 4 warnings in 0.17s =========`

What command will result into the outcome given above?
  1. question figure
    text
    ```
    pytest test_file.py -m marker4
    ```
  2. question figure
    text
    ```
    pytest test_file.py -m marker1
    ```
  3. question figure
    text
    ```
    pytest test_file.py -m marker2
    ```
  4. question figure
    text
    ```
    pytest test_file.py -m marker3
    ```
Comprehension passage - the questions below it refer to this
Based on the above data, answer the given subquestions. question figure
Q31MCQ3 marks
question figure
Text of the picture (copyable)
What will be output on the terminal for the command python file.py course 2?
  1. question figure
    text
    course found App Dev II
  2. question figure
    text
    course found App Dev III
  3. question figure
    text
    No course found!
  4. question figure
    text
    ```text
    course found App Dev I
    course found App Dev II
    ```
Q32MCQ3 marks
question figure
Text of the picture (copyable)
What will be output on the terminal for the command python file.py course 3?
  1. question figure
    text
    course found App Dev III
  2. question figure
    text
    ```
    course found App Dev I
    course found App Dev II
    ```
  3. question figure
    text
    ```
    course found App Dev I
    course found App Dev II
    course found App Dev III
    ```
  4. question figure
    text
    ```
    IndexError: list index out of range
    ```

Answer key

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

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, principles, and equations essential for the "Modern Application Development I" exam, along with Mermaid knowledge graphs to visualize relationships.



1. Core Topics & Concepts

A. Python & Templating Engines

Key Concepts:

  1. String Templating:

    • string.Template (uses $var syntax).
    • jinja2.Template (uses {{ var }} syntax).
    • Methods:

      • substitute() (raises KeyError if a key is missing).
      • safe_substitute() (ignores missing keys).
      • render() (Jinja2 method for substitution).
  1. Command-Line Arguments (sys.argv):

    • sys.argv[0] = Script name.
    • sys.argv[1:] = User-provided arguments.
  1. Python Logging:

    • Levels: DEBUG, INFO, WARNING, ERROR, CRITICAL.
    • logging.basicConfig(level=logging.WARNING, format='...').
    • logging.exception() for errors.

Equations/Code Snippets:

### Jinja2 vs. string.Template
from jinja2 import Template
from string import Template as StringTemplate

jinja_temp = Template("Hello {{ name }}!")
string_temp = StringTemplate("Hello $name!")

### Logging
import logging
logging.basicConfig(level=logging.WARNING)
logging.warning("This is a warning!")

B. Flask (Web Framework)

Key Concepts:

  1. Routing:

    • @app.route('/path/<type:var>') (e.g., <string:url>, <path:url>).
    • Path vs. String:

      • /home/<string:url> → Matches single segment (e.g., /home/abc).
      • /home/<path:url> → Matches multiple segments (e.g., /home/abc/def).
  1. HTTP Methods:

    • GET (default), POST, PUT, DELETE.
    • Access data:

      • request.args (for GET query parameters).
      • request.json (for POST/PUT JSON data).
  1. Jinja2 in Flask:

    • Render templates: render_template("file.html", data=dict).
    • Macros: Reusable HTML blocks.
    • Conditionals/Loops:

      {% if condition %} ... {% endif %}
      {% for item in list %} ... {% endfor %}
  1. Flask-RESTful:

    • Define resources with GET, POST, PUT, DELETE methods.
    • Use reqparse.RequestParser() for input validation.
  1. Testing:

    • app.test_request_context() for simulating requests.
    • url_for('endpoint', param=value) for generating URLs.

Equations/Code Snippets:

### Flask Route with Path/String
@app.route('/home/<path:url>')  # Matches /home/a/b/c
def path_route(url):
    return f"Path: {url}"

### HTTP Methods
from flask import request
@app.route('/data', methods=['GET', 'POST'])
def handle_data():
    if request.method == 'POST':
        data = request.json
    else:
        data = request.args

### Flask-RESTful
from flask_restful import Resource
class UserResource(Resource):
    def get(self, user_id):
        return {"user": user_id}

C. HTML & JavaScript

Key Concepts:

  1. HTML Forms:

    • method="POST/GET".
    • action="/submit" (endpoint).
    • Input types: text, submit, etc.
  1. JavaScript Console:

    • console.log() for debugging.
    • window.alert() (popup), document.write() (writes to HTML).
  1. CSS Specificity:

    • !important > Inline > ID (#id) > Class (.class) > Element (p).
    • Example:

      .two { color: red !important; }  /* Highest priority */
      #two { color: green; }            /* Lower priority */

Equations/Code Snippets:

<!-- HTML Form -->
<form action="/submit" method="POST">
  <input type="text" name="username">
  <input type="submit" value="Submit">
</form>

<!-- JavaScript -->
<script>
  console.log("Debug message");
  document.write("Hello World");
</script>

D. Git & Version Control

Key Concepts:

  1. Branching:

    • git branch <name> (create).
    • git checkout <branch> (switch).
    • git merge <branch> (combine).
  1. Commands:

    • git add, git commit -m "message", git push.

E. Databases & SQLAlchemy

Key Concepts:

  1. Relationships:

    • One-to-Many: Foreign key in the "many" table (e.g., book_id in Section).
    • Many-to-Many: Junction table with two foreign keys.
  1. SQLAlchemy:

    • Column(Integer, ForeignKey('table.id')).
    • relationship("Model", back_populates="field").

Equations/Code Snippets:

### One-to-Many (Book → Sections)
class Book(Base):
    __tablename__ = "books"
    id = Column(Integer, primary_key=True)
    sections = relationship("Section", back_populates="book")

class Section(Base):
    __tablename__ = "sections"
    id = Column(Integer, primary_key=True)
    book_id = Column(Integer, ForeignKey("books.id"))
    book = relationship("Book", back_populates="sections")

F. Testing (Pytest)

Key Concepts:

  1. Fixtures:

    • @pytest.fixture for reusable setup.
  2. Markers:

    • @pytest.mark.name for selective test execution.
    • Run with pytest -m "marker".
  3. Assertions:

    • assert condition, "message".

Equations/Code Snippets:

### Pytest Example
import pytest
@pytest.mark.math
def test_add():
    assert 1 + 1 == 2

### Run marked tests
pytest -m "math" test_file.py

G. Networking & Performance

Key Concepts:

  1. Bandwidth Calculation:

    • Formula: \[ \text{Bandwidth (GB/s)} = \frac{\text{Bus Width (bits)} \times \text{Clock Speed (Hz)} \times \text{Data Rate}}{\text{Bits per Byte (8)} \times 10^9} \]
    • Example: 64-bit bus, 2 GHz, DDR (2 transfers/cycle): \[ \text{Bandwidth} = \frac{64 \times 2 \times 10^9 \times 2}{8 \times 10^9} = 32 \text{ GB/s} \]
  1. Latency:

    • Round-trip time (RTT) = \( \frac{2D}{v} \), where:

      • \( D \) = distance,
      • \( v \) = speed of light in the medium.

H. Software Testing Types

TypeDescription
White Box TestingTests internal logic (code coverage).
Black Box TestingTests functionality without code knowledge.
User Acceptance TestingEnd-users validate the system (e.g., Beta Testing).
System TestingTests the complete system (end-to-end).
Automation TestingUses tools (e.g., Selenium) to simulate users.

Graph 2: Flask Ecosystem

Graph 3: HTML/JavaScript/CSS

Graph 4: Databases & SQLAlchemy

Graph 5: Testing & Git

Graph 6: Networking


3. Key Equations (Math/Performance)

  1. Bandwidth (GB/s): \[ \text{Bandwidth} = \frac{\text{Bus Width (bits)} \times \text{Clock Speed (Hz)} \times \text{Data Rate}}{8 \times 10^9} \]

    • Example: 64-bit, 2 GHz, DDR (2x): \[ \frac{64 \times 2 \times 10^9 \times 2}{8 \times 10^9} = 32 \text{ GB/s} \]
  1. Latency (RTT): \[ \text{RTT} = \frac{2D}{v} \]

    • \( D \): Distance (meters).
    • \( v \): Speed of light in medium (m/s).

4. Exam Tips

  1. Flask:

    • Remember /<path:var> vs. /<string:var>.
    • request.args (GET) vs. request.json (POST).
  2. Jinja2:

    • {{ var }} for variables, {% %} for logic.
    • safe_substitute vs. substitute.
  3. Testing:

    • Pytest markers (-m) and fixtures.
  4. Git:

    • git branch (create), git checkout (switch).
  5. Networking:

    • Bandwidth depends on bus width, clock speed, and data rate.
  6. CSS:

    • !important overrides all other styles.