MAD Study Hub

Home / Past papers / MAD1 Quiz 2 / this paper

IIT M DIPLOMA AN4 EXAM QDD4 03 Dec 2023 - 03 Dec 2023

MAD1 Quiz 216 questions50 marks11 MCQ · 5 MSQDiploma / QDD4
Elapsed 00:00
Q1MCQ4.5 marks
question figure
Text of the picture (copyable)
Consider the schema for the 'student' table created in SQLite database using
flask-sqlalchemy.

```sql
CREATE TABLE "student" (
    "s_id"          INTEGER,
    "roll_number"   TEXT NOT NULL UNIQUE,
    "first_name"    TEXT NOT NULL,
    "last_name" TEXT NOT NULL,
    PRIMARY KEY("s_id" AUTOINCREMENT)
);
```

What will be the output of the flask_sqlalchemy command given below?

```python
>>> s1 = Student(roll_number = "M01", first_name = "John", last_name = "Doe")
>>> db.session.add(s1)
>>> s2 = Student(roll_number = "M02", first_name = "John", last_name = "Luther")
>>> db.session.add(s2)
>>> s3 = Student(roll_number = "M03", first_name = "Harry", last_name = "Doe")
>>> db.session.add(s3)
>>> db.session.commit()
>>> user1= Student.query.filter_by(first_name="John").first()
>>> user1.first_name= "Harry"
>>> user1.last_name= "Luther"
>>> db.session.commit()
>>> s1 = Student.query.all()
>>> for student in s1:
...     print(student.first_name)
...     print(student.last_name)
```
  1. question figure
    text
    Harry
    Luther
    Harry
    Luther
    Harry
    Doe
  2. question figure
    text
    Harry
    Luther
    John
    Luther
    Harry
    Doe
  3. question figure
    text
    Harry
    Luther
    Harry
    Doe
    Harry
    Doe
  4. question figure
    text
    Harry
    Doe
    John
    Luther
    Harry
    Doe
Q2MCQ4.5 marks
Consider the following flask application. question figure Consider the following flask application.
Text of the picture (copyable)
```python
from flask import Flask, abort
app = Flask(__name__)

users = ["admin", "user_1", "user_2", "user_3"]

@app.route('/home/<string:username>', methods = ['POST'])
def home(username):
    if username in users:
        return f"<h1>Hello {username}, Welcome!</h1>"
    else:
        abort(404)

@app.errorhandler(404)
def user_error_1(error):
    return "<h1>The user you are looking for is invalid.</h1>"

@app.errorhandler(405)
def user_error_2(error):
    return "<h1>Please check the web request.</h1>"

app.run()
```

If the application is running locally on http://127.0.0.1:5000. What will be rendered on the browser for url http://127.0.0.1:5000/home/user_4 ?
  1. question figure
    text
    Hello user_4, Welcome!
  2. question figure
    text
    The user you are looking for is invalid.
  3. question figure
    text
    Not Found
  4. question figure
    text
    Please check the web request
Q3MSQ3 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('/home')
def index():
    return 'Mad-I Student Data'

@app.route('/student/<student_name>/<int:student_id>')
def profile(student_name,student_id):
    return f'Student Name:{student_name},Student ID:{student_id}'

with app.test_request_context():
    #== print statement ==#
```
  1. question figure
    text
    If `print statement` is replaced by:
    ```python
    print(url_for('index')),
    ```
    the output on the terminal will be:
    Mad-I Student Data
  2. question figure
    text
    If #=== print statement ===# is replaced by;
    ```python
    print(url_for('profile', student_name='John', student_id=101)),
    ```
    the output on the terminal will be;
    /student?student_name=John&student_id=101
  3. question figure
    text
    If #== print statement ==# is replaced by;
    ```python
    print(url_for('index')),
    ```
    the output on the terminal will be;
    /home
  4. question figure
    text
    If #== print statement ==# is replaced by;
    ```python
    print(url_for('profile',student_name='John',student_id=101))
    ```
    the output on the terminal will be;
    /student/John/101
Q4MSQ3 marksselect all that apply
question figure
Text of the picture (copyable)
Consider the following flask application.
app.py

```python
from flask import Flask, abort

app = Flask(__name__)

@app.route('/<uname>')
def index(uname):
    if uname[0].isdigit():
        abort(400, "Bad Request")
    return '<h1>Good Username</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/MAD1?uname=102 the browser will render
    Bad Request.
  2. question figure
    text
    For URL http://127.0.0.1:5000/MAD1?uname=102 the browser will render
    Good Username.
  3. question figure
    text
    For URL http://127.0.0.1:5000/102?uname=MAD1 the browser will render
    Bad Request.
  4. question figure
    text
    For URL http://127.0.0.1:5000/102?uname=MAD1 the browser will render
    Good Username.
Q5MCQ2 marks
In the context of in-memory databases, what is the primary function of an index?
  1. To encrypt sensitive data
  2. To optimize query performance by speeding up data retrieval
  3. To manage data replication
  4. To store metadata about the database structure
Q6MCQ2 marks
question figure
Text of the picture (copyable)
Consider the following python code snippet.

```python
from string import Template as T1
from jinja2 import Template as T2
temp = "A student needs to complete $c1 level to get to the {{c2}} level."

temp = T1(temp)
out = temp.substitute({'c1':'foundation', 'c2':'diploma'})
print(out)
out= T2(out)
print(out.render({'c2':'diploma'}))
```

What is the generated output on python console?
  1. A student needs to complete foundation level to get to the diploma level.A student needs to complete foundation level to get to the diploma level.
  2. A student needs to complete $c1 level to get to the {{c2}} level.A student needs to complete foundation level to get to the diploma level.
  3. A student needs to complete foundation level to get to the {{c2}} level.A student needs to complete foundation level to get to the diploma level.
  4. A student needs to complete foundation level to get to the {{diploma}} level.A student needs to complete foundation level to get to the diploma level.
Q7MCQ2 marks
In the context of API documentation, what is typically provided to describe the available endpoints, request parameters and response formats?
  1. API documentation or API reference
  2. API key
  3. Software source code
  4. OAuth tokens
Comprehension passage - the questions below it refer to this
question figure
Q8MCQ2 marks
question figure
Text of the picture (copyable)
What relationship do the tables
"channel" and "video" share.
  1. One-to-one
  2. One-to-many
  3. Many-to-one
  4. Many-to-many
Q9MSQ3 marksselect all that apply
question figure
Text of the picture (copyable)
If "ch1" is a channel object created in
"channel" table with primary key 1, then the
correct way(s) of creating a video object
"vid1" in the video table that belongs to
"ch1" object is/are ______. (let
"name" of the video be "Intro to Python")
  1. question figure
    text
    ```python
    >>> vid1 = Video(name = "Intro to Python", channel = ch1)
    >>> db.session.add(vid1)
    >>> db.session.commit()
    ```
  2. question figure
    text
    ```python
    >>> vid1 = Video(name = "Intro to Python", channel = 1)
    >>> db.session.add(vid1)
    >>> db.session.commit()
    ```
  3. question figure
    text
    ```python
    >>> vid1 = Video(name = "Intro to Python", playlist = ch1)
    >>> db.session.add(vid1)
    >>> db.session.commit()
    ```
  4. question figure
    text
    ```python
    >>> vid1 = Video(name = "Intro to Python", playlist = 1)
    >>> db.session.add(vid1)
    >>> db.session.commit()
    ```
Comprehension passage - the questions below it refer to this
question figure
Q10MCQ3 marks
question figure
Text of the picture (copyable)
Map the api resources in column A with the correct URLs given in column B.

| Column A | Column B |
|---|---|
| 1. GET | a. http://127.0.0.1:5000/student |
| 2. PUT | b. http://127.0.0.1:5000/api/Meera |
| 3. POST | c. http://127.0.0.1:5000/app/STU103/Sociology |
  1. question figure
    text
    1 → c, 2 → a, 3 → b
  2. question figure
    text
    1 → a, 2 → b, 3 → c
  3. question figure
    text
    1 → b, 2 → a, 3 → c
  4. question figure
    text
    1 → b, 2 → c, 3 → a
Q11MCQ3 marks
question figure
Text of the picture (copyable)
If the app first receives the request,
```
curl http://127.0.0.1:5000/app/STU105/Robotics -X PUT
```
what will be the final output on the shell after
writing the following lines of code one
below the other in the Python shell?
```python
>>> from app import *
>>> students = Student.query.filter_by(name = "Ramesh").all()
>>> for student in students:
...     print(student.course)
```
  1. question figure
    text
    Physics
    Physics
  2. question figure
    text
    Robotics
    Robotics
  3. question figure
    text
    Physics
    Robotics
  4. question figure
    text
    Robotics
    Physics
Q12MCQ3 marks
Consider a client which is located 3000 km from the server makes a request through the cable. Suddenly after the request reaches the server, the cable breaks and the response is now to be sent to the client via air. This change of medium caused an additional delay of 30 ms at the server end. How long will the client have to wait for receiving the response? (speed on cable = 2e8 m/s and in air 3e8 m/s)
  1. 55 milliseconds
  2. 50 milliseconds
  3. 80 milliseconds
  4. 60 milliseconds
Q13MCQ3 marks
The throughput of a Solid State Device (SSD) is 180 MB/sec. If it is to be replaced by a standard HDD whose lens can read data with the rate of 4.8 Megabits/revolution. What should be the speed of rotation (in RPM) of HDD to get a throughput equal to that of the SDD?
  1. 300
  2. 900
  3. 12000
  4. 18000
Q14MCQ3 marks
What will be the output of the following Python code snippet? question figure What will be the output of the following Python code snippet?
Text of the picture (copyable)
```python
def modify(func):
    def wrapper(n):
        mylist = []
        for i in range(1, n + 1):
            if n % i == 0:
                mylist.append(i)
        return mylist
    return wrapper

@modify
def myFunc(n):
    mylist = []
    for i in range(1, n + 1):
        if i % 2 == 0:
            mylist.append(i)
    return mylist

print(myFunc(14))
```
  1. question figure
    text
    ```
    [1, 3, 5, 7, 9, 11, 13]
    ```
  2. question figure
    text
    ```
    [2, 4, 6, 8, 10, 12, 14]
    ```
  3. question figure
    text
    ```
    [1, 2, 7, 14]
    ```
  4. question figure
    text
    ```
    [1, 3, 5, 7, 11, 13]
    ```
Q15MSQ4.5 marksselect all that apply
Consider the following flask view function defined to add a product and select correct statement(s). question figure Consider the following flask view function defined to add a product and select correct statement(s).
Text of the picture (copyable)
```python
@app.route("/add", methods = ['GET', 'POST'])
def add_product():
    if request.method == 'POST':
        name = request.form.get('name')
        category = request.form.get('category')
        if name == "":
            return redirect('/add')
        if category == "":
            return redirect('/add')
        return f"Product {name} is added in {category} category."

    return """
    <form action="/add" method="post">
        Product Name: <input type="text" name="name"
        minlength="2"><br>
        Product Category: <input type="text" name="category"
        required><br>
        <input type="submit" value="Add Product">
    </form>
    """
```
  1. question figure
    text
    The form to add the product is statically generated.
  2. question figure
    text
    The form to add the product is dynamically generated.
  3. question figure
    text
    The form rendered for `/add` endpoint has frontend validation.
  4. question figure
    text
    The form rendered for `/add` endpoint has backend validation.
Q16MSQ4.5 marksselect all that apply
Consider the following Python code snippet. question figure Consider the following Python code snippet. Which of the following statements is/are correct?
Text of the picture (copyable)
Filename: log.py
```python
import logging
import sys

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

num1, num2 = int(sys.argv[1]), int(sys.argv[2])

if num2 > 0:
    logging.debug(f"Division {num1}/{num2} is possible")
else:
    logging.critical("FATAL - Division by zero is not possible")
```
  1. question figure
    text
    For the command: `python log.py 12 24`
    The output on the terminal will be:
    ```
    DEBUG - Division 12/24 is possible
    ```
  2. question figure
    text
    For the command: `python log.py 0 24`
    The output on the terminal will be:
    `DEBUG - Division 0/24 is possible`
  3. question figure
    text
    For the command: `python log.py 15 0`
    The output on the terminal will be:
    `CRITICAL - FATAL - Division by zero is not possible`
  4. question figure
    text
    For the command: python log.py 0 0
    The output on the terminal will be:
    CRITICAL - FATAL - Division by zero is not possible

Answer key

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