MAD Study Hub

Home / Past papers / MAD1 Quiz 2 / this paper

2024 Aug04: IIT M AN EXAM QIM4 - 04 Aug 2024

MAD1 Quiz 216 questions50 marks10 MCQ · 6 MSQafternoon / QIM4
Elapsed 00:00
Q1MCQ2 marks
Read the statements given below carefully and select the correct option. Statement 1: The GET method is the same as the HEAD method. It is used to transfer the header section only. Statement 2: The GET method retrieves information from the given server using a given URI.GET request can retrieve the data.
  1. Both statements 1 and 2 are correct
  2. Both statements 1 and 2 are incorrect
  3. Statement 1 is correct but statement 2 is incorrect
  4. Statement 1 is incorrect but statement 2 is correct
Q2MCQ2 marks
question figure
Text of the picture (copyable)
Consider the below flask_sqlalchemy data models "Product", "Supplier" and "Supply" given in the code below.

```python
class Product(db.Model):
    __tablename__ = "product"
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String, nullable=False)

class Supplier(db.Model):
    __tablename__ = "supplier"
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String, nullable=False)
    address = db.Column(db.String, nullable=True)

class Supply(db.Model):
    __tablename__ = "supply"
    id = db.Column(db.Integer, primary_key=True)
    product_id = db.Column(db.Integer, db.ForeignKey("product.id"))
    supplier_id = db.Column(db.Integer, db.ForeignKey("supplier.id"))
```

What will be the cardinality of the "Product" and "Supplier" relationship?
  1. One to One
  2. One to Many
  3. Many to Many
  4. Many to One
Q3MCQ3 marks
A certain video on the web occupies 3 gigabytes of memory of the server. If the number of viewers of the video over time is given by the curve shown below and assuming that each viewer requires an individual connection to the server to view the video, what should be the minimum RAM requirement of the server that can process requests from all the viewers simultaneously at any point of time? question figure A certain video on the web occupies 3 gigabytes of memory of the server. If the number of viewers of the video over time is given by the curve shown below and assuming that each viewer requires an individual connection to the server to view the video, what should be the minimum RAM requirement of the server that can process requests from all the viewers simultaneously at any point of time?
Text of the picture (copyable)
This is an area chart showing "No. of viewers (in Hundreds)" on the y-axis and "Time (minutes)" on the x-axis.

**Y-axis (No. of viewers (in Hundreds)):**
*   Ticks at 0, 5, 10, 15, 20.

**X-axis (Time (minutes)):**
*   Ticks at 0, 10, 20, 30, 40, 50, 60.

**Data points (approximate):**
*   (0, 11.5)
*   (10, 7)
*   (15, 9)
*   (20, 13)
*   (23, 18.5) - Peak 1
*   (30, 6.5)
*   (35, 4) - Valley
*   (40, 8)
*   (45, 13)
*   (47, 17) - Peak 2
*   (50, 15)
*   (55, 6)
*   (60, 4)

The area under the line is filled with a light red color.
  1. 1.9 GB
  2. 5.7 GB
  3. 1.9 TB
  4. 5.7 TB
Q4MCQ3 marks
question figure
Text of the picture (copyable)
Consider the following Python code.

**app.py**
```python
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
import os

app_dir = os.path.dirname(os.path.abspath(__file__))
db_file = "sqlite:///course_database.sqlite3"

app = Flask(__name__)
app.app_context().push()
app.config["SQLALCHEMY_DATABASE_URI"] = db_file
app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False

db = SQLAlchemy(app)

class MaxScores(db.Model):
    __tablename__ = "max_scores"
    course_id = db.Column(db.String(10), nullable=False, primary_key=True)
    high_score = db.Column(db.Integer)
    term_year = db.Column(db.String(10))
```
Using *MaxScores* data model in the above “*app.py*”. What is the correct sequence of python commands to insert *MaxScores* record?
  1. question figure
    text
    ```python
    >>> from app.py import *
    >>> db.create_all()
    >>> s1 = MaxScores(course_id='cs2002', high_score=86, term_year='Jan-2023')
    >>> db.session.add(s1)
    >>> db.session.commit()
    ```
  2. question figure
    text
    ```python
    >>> from app.py import *
    >>> db.create_all()
    >>> s1 = MaxScores('cs2002', 86, 'Jan-2023')
    >>> db.session.add(s1)
    >>> db.session.commit()
    ```
  3. question figure
    text
    ```python
    >>> from app.py import *
    >>> db.create_all()
    >>> s1 = MaxScores('cs2002', 86, 'Jan-2023')
    >>> db.commit()
    >>> db.add(s1)
    ```
  4. question figure
    text
    ```python
    >>> from app.py import *
    >>> db.create_all()
    >>> s1 = MaxScores(course_id='cs2002',high_score=86,term_year='Jan-2023')
    >>> db.session.commit()
    >>> db.session.add(s1)
    ```
Q5MCQ3 marks
Consider the following Python code snippet, and select the correct output list if the code is run on the terminal. question figure Consider the following Python code snippet, and select the correct output list if the code is run on the terminal.
Text of the picture (copyable)
```python
def modify(func):
    def wrapper(l):
        res = func(l)
        return res[::-1]
    return wrapper

def update(func):
    def wrapper(l):
        res = func(l)
        return list(map(lambda x: x/2,res))
    return wrapper

@modify
@update
def mylist(l):
    out_list = []
    for i in l:
        out_list.append(i**2)
    return out_list

print(mylist([2,4,1,7,5,9]))
```
  1. [0.25, 1, 4, 6.26, 12.25, 20.25]
  2. [1, 4, 0.25, 12.25, 6.25, 20.25]
  3. [40.5, 12.5, 24.5, 0.5, 8.0, 2.0]
  4. [0.5, 2.0, 8.0, 12.5, 24.5, 40.5]
Q6MSQ3 marksselect all that apply
Consider the following flask application. question figure Consider the following flask application.
Text of the picture (copyable)
```python
from flask import Flask, request
app = Flask(__name__)

@app.route('/home')
def home():
    var_a = request.args.get('method')
    if var_a == "GET":
        return """
        <body style="background-color: lightgray; color: 
purple;text-align: center;font-weight: bold;">
        <p>IIT</p>
        <p>MADRAS</p>
        </body>
        """
    elif var_a == "POST":
        return """
        <body style="background-color: lightgray; color: 
purple;text-align: center;font-weight: bold;">
        <p>IIT</p>
        <span>MADRAS</span>
        </body>
        """
    else:
        return "Invalid Method"
app.run(debug=True)
```
If the application is running locally on http://127.0.0.1:5000 then which of the following statements are correct?
  1. question figure
    text
    The browser will render aesthetically similar output for
    http://127.0.0.1:5000/home?method=POST and
    http://127.0.0.1:5000/home?method=GET
  2. question figure
    text
    The browser will render aesthetically different output for
    http://127.0.0.1:5000/home?method=POST and
    http://127.0.0.1:5000/home?method=GET
  3. question figure
    text
    The browser will render Method Not Allowed error for http://127.0.0.1:5000/home
  4. question figure
    text
    The browser will render Invalid Method error for http://127.0.0.1:5000/home
Q7MSQ3 marksselect all that apply
question figure
Text of the picture (copyable)
Consider the following code.

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

trains_list = [
    {"train_no": 12842, "source": "Madras", "destination": "Howrah"},
    {"train_no": 12727, "source": "VSKP", "destination": "HYD"},
    {"train_no": 12434, "source": "Delhi", "destination": "Madras"},
]
app = Flask(__name__)
api = Api(app)

class TrainsApi1(Resource):
    def get(self, tno):
        for train in trains_list:
            if train["train_no"] == tno:
                return train
        return None

class TrainsApi2(Resource):
    def get(self):
        return trains_list

api.add_resource(TrainsApi1, "/api/ver1/<int:tno>")
api.add_resource(TrainsApi2, "/api/ver2/")

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

Assume that the above flask code is running locally on http://127.0.0.1:5000/. Which of the below URL(s) requests renders train data without errors?
  1. http://127.0.0.1:5000/api/ver1/12727
  2. http://127.0.0.1:5000/api/12727
  3. http://127.0.0.1:5000/ver2/12727
  4. http://127.0.0.1:5000/api/ver2
Comprehension passage - the questions below it refer to this
Based on the above data, answer the given subquestions. question figure
Q8MSQ3 marksselect all that apply
question figure
Text of the picture (copyable)
What should be the code to run the
application, and the URL respectively
such that the browser gives
output as: Welcome to Application Development!?
  1. question figure
    text
    Code: python app.py Application Development Java
    URL: http://127.0.0.1:5000/course?course=Java
  2. question figure
    text
    Code:
    ```
    python app.py Application Development Java
    ```
    URL:
    ```
    http://127.0.0.1:5000/course=Application Development
    ```
  3. question figure
    text
    Code: python app.py "Application Development" Java
    URL: http://127.0.0.1:5000/course?course=Java
  4. question figure
    text
    Code:
    ```
    python app.py "Application Development" DBMS
    ```
    URL:
    ```
    http://127.0.0.1:5000/course?course=Application Development
    ```
Q9MCQ2 marks
question figure
Text of the picture (copyable)
What will be the output given by
browser if the application is run with
command `python app.py Application Development DBMS`
on terminal with URL `http://127.0.0.1:5000?course=DBMS` ?
  1. question figure
    text
    Welcome to Application Development!
  2. question figure
    text
    Welcome to DBMS !
  3. question figure
    text
    Invalid Data
  4. question figure
    text
    Not Found
Comprehension passage - the questions below it refer to this
question figure
Q10MSQ3 marksselect all that apply
question figure
Text of the picture (copyable)
Which of the following is/are the
correct URLs for retrieving the user
from the database with "id": "103"?
  1. http://127.0.0.1:5000/103
  2. http://127.0.0.1:5000/user/103
  3. http://127.0.0.1:5000?id=103
  4. http://127.0.0.1:5000/user?id=103
Q11MCQ3 marks
question figure
Text of the picture (copyable)
Which of the following URLs will trigger
the "get_user" controller in the given
application.
  1. question figure
    text
    http://127.0.0.1:5000/104
  2. question figure
    text
    http://127.0.0.1:5000/user/104
  3. question figure
    text
    ```
    http://127.0.0.1:5000?id=104
    ```
  4. question figure
    text
    http://127.0.0.1:5000/user?id=104
Q12MCQ4.5 marks
You have a DRAM module with bus width of 64 bits, clock speed of 400 MHz, and operating in DDR (double-data-rate or two values per clock cycle) mode. What is the maximum memory bandwidth in Gigabytes per second achievable with this module if it is working in dual channel mode (two memory interfaces are used)?
  1. 51.2
  2. 102.4
  3. 25.6
  4. 12.8
Q13MCQ4.5 marks
question figure
Text of the picture (copyable)
Two data models "Student" and "Sport" are to be created in the database with one-to-many relationship using *flask_sqlalchemy*. Which of the following is the correct implementation of the above two data models?
  1. question figure
    text
    ```python
    class Student(db.model):
        id=db.Column(db.Integer, primary_key=True)
        Name = db.Column(db.String, nullable=False)
        stud_id=db.Column(db.Integer, db.ForeignKey('sport.id'))
        sports=db.relationship('Sport', backref='student')
    
    class Sport(db.model):
        id=db.Column(db.Integer, primary_key=True)
        sport_name=db.Column(db.String, nullable=False)
    ```
  2. question figure
    text
    ```python
    class Student(db.model):
        id=db.Column(db.Integer, primary_key=True)
        Name = db.Column(db.String, nullable=False)
        sports=db.relationship('Sport', backref='sport')
    
    class Sport(db.model):
        id=db.Column(db.Integer, primary_key=True)
        sport_name=db.Column(db.String, nullable=False)
        stud_id=db.Column(db.Integer, db.ForeignKey('sport.id'))
    ```
  3. question figure
    text
    ```python
    class Student(db.model):
        id=db.Column(db.Integer, primary_key=True)
        Name = db.Column(db.String, nullable=False)
        sports=db.relationship('Sport', backref='student')
    
    class Sport(db.model):
        id=db.Column(db.Integer, foreign_key=True)
        sport_name=db.Column(db.String, nullable=False)
        stud_id=db.Column(db.Integer, db.ForeignKey('student.id'))
    ```
  4. question figure
    text
    ```python
    class Student(db.model):
        id=db.Column(db.Integer, primary_key=True)
        Name = db.Column(db.String, nullable=False)
        sports=db.relationship('Sport', backref='student')
    
    class Sport(db.model):
        id=db.Column(db.Integer, primary_key=True)
        sport_name=db.Column(db.String, nullable=False)
        stud_id=db.Column(db.Integer, db.ForeignKey('student.id'))
    ```
Q14MCQ4.5 marks
question figure
Text of the picture (copyable)
Consider the following Python code snippet.
Filename: code.py

```python
import logging
import sys

logging.basicConfig(format='%(levelname)s:%(message)s', level=logging.INFO)

logging.warning('This is only for testing.')

if sys.argv[1] == 'info':
    logging.info('This code is working as expected.')

if sys.argv[1] == 'debug':
    logging.debug('This code may have issues, debugging...')

logging.warning('code execution complete!')
```

What will be output on the terminal is the above code snippet is run on the terminal using command: `python code.py debug`
  1. question figure
    text
    ```
    WARNING:This is only for testing.
    INFO: This code is working as expected
    WARNING:code execution complete!
    ```
  2. question figure
    text
    ```
    WARNING:This is only for testing.
    DEBUG: This code may have issues, debugging...
    WARNING:code execution complete!
    ```
  3. question figure
    text
    ```
    WARNING:This is only for testing.
    WARNING:code execution complete!
    ```
  4. question figure
    text
    ```
    INFO: This code is working as expected
    DEBUG: This code may have issues, debugging...
    ```
Q15MSQ2 marksselect all that apply
question figure
Text of the picture (copyable)
Consider the following flask application.

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

@app.route('/login/<id>')
def login(id):
    if id:
        if id.isalpha():
            abort(400, "Bad Request: Invalid ID")
        return f'<h1>Your ID is: {id}</h1>'
    return f'<h1>Invalid ID</h1>'

app.run(debug=True)
```

Which of the following statements is/are true if the application is running locally on http://127.0.0.1:5000 ?
  1. question figure
    text
    For URL http://127.0.0.1:5000/login?id=MAD-I the browser will render
    Bad Request: Invalid ID
  2. question figure
    text
    For URL http://127.0.0.1:5000/login/ the browser will render
    Invalid ID
  3. question figure
    text
    For URL http://127.0.0.1:5000/login/CS2003 the browser will render
    Your ID is: CS2003
  4. question figure
    text
    For URL http://127.0.0.1:5000/login/PDSA the browser will render Bad
    Request: Invalid ID
Q16MSQ4.5 marksselect all that apply
Consider the following HTML Document and select the correct statement(s) from the following if a user types the password “mad1password” in the password field letter by letter. question figure Consider the following HTML Document and select the correct statement(s) from the following if a user types the password “mad1password” in the password field letter by letter.
Text of the picture (copyable)
```html
<!DOCTYPE html>
<html lang="en">
<head>
    <title>Login Form</title>
    <style>
        input[type="password"]:valid{
            background-color: green;
        }
        input[type="password"]:invalid{
            background-color: red;
        }
    </style>
</head>
<body>
    <div class="login-form">
        <h2>Login</h2>
        <form>
            E-mail: <input type="email" id="email" name="email" required>
            Password: <input type="password" id="password" name="password"
            required minlength="5" maxlength="8">
            <input type="submit" value="Login">
        </form>
    </div>
</body>
</html>
```
  1. The HTML form is integrated with backend validation.
  2. The HTML form is integrated with Frontend HTML5 validation.
  3. The background colour of the password field remains red for the first 4 letters,then turns green for the next 4 letters, and then again turns red for the remaining letters.
  4. The background colour of the password field remains red for the first 4 letters,then turns green for the next 4 letters, and then remains green for the remaining allowable letters.

Answer key

  1. Q1 (MCQ, 2 marks): D
  2. Q2 (MCQ, 2 marks): C
  3. Q3 (MCQ, 3 marks): D
  4. Q4 (MCQ, 3 marks): A
  5. Q5 (MCQ, 3 marks): C
  6. Q6 (MSQ, 3 marks): A, D
  7. Q7 (MSQ, 3 marks): A, D
  8. Q8 (MSQ, 3 marks): C, D
  9. Q9 (MCQ, 2 marks): D
  10. Q10 (MSQ, 3 marks): B, D
  11. Q11 (MCQ, 3 marks): D
  12. Q12 (MCQ, 4.5 marks): D
  13. Q13 (MCQ, 4.5 marks): D
  14. Q14 (MCQ, 4.5 marks): C
  15. Q15 (MSQ, 2 marks): C, D
  16. Q16 (MSQ, 4.5 marks): B, D