MAD Study Hub

Home / Past papers / MAD1 Quiz 2 / this paper

IIT M FOUNDATION AN2 EXAM QPF2 06 Aug 2023 - 06 Aug 2023

MAD1 Quiz 216 questions50 marks11 MCQ · 4 MSQ · 1 SAFoundation / QPF2
Elapsed 00:00
Q1MCQ2 marks
question figure
Text of the picture (copyable)
Consider the following flask application and select the correct option if the application is running locally on http://127.0.0.1:5000.

```python
from flask import Flask

app = Flask(__name__)

@app.route('/work')
@app.route('/home')
def my_task():
    return "<h1>Hello! Reporting for my task</h1>"

app.run()
```
  1. question figure
    text
    The application will return 200 OK status code for /home endpoint only
  2. question figure
    text
    The application will return 200 OK status code for /work endpoint only
  3. question figure
    text
    The application will return 200 OK status code for both the endpoints
  4. question figure
    text
    The application will throw an AssertionError for both the endpoints
Q2MCQ2 marks
question figure
Text of the picture (copyable)
Which of the following statements about OpenAPI Specification (OAS) is true?
  1. OAS is a programming language used for building APIs.
  2. OAS is a way to describe interfaces for building RESTful APIs.
  3. OAS is a tool used for testing the performance of APIs.
  4. OAS is a software library used for authenticating API requests.
Q3MCQ2 marks
question figure
Text of the picture (copyable)
Map the terms in column A with their correct interpretations in column B.

| | Column A | | Column B |
|---|---|---|---|
| a | Scale up | 1 | financial transactions |
| b | ACID | 2 | adding more physical servers |
| c | Scale out | 3 | increasing RAM |
| d | BASE | 4 | social media |
  1. question figure
    text
    a → 3, b → 1, c → 2, d → 4
  2. question figure
    text
    a → 4, b → 2, c → 1, d → 3
  3. question figure
    text
    a → 4, b → 3, c → 1, d → 2
  4. question figure
    text
    a → 3, b → 2, c → 1, d → 4
Q4MCQ2 marks
question figure
Text of the picture (copyable)
Consider the following view function.

```python
@app.route('/student', methods = ['GET', 'POST'])
def show_student():
    std = request.args
    details = {
        'Department': std['dept'],
        'Course-level': std['level'],
        'Course': std['course']
    }
    return details
```

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/student/Electrical/Diploma/MAD1
    ```
  2. question figure
    text
    ```
    http://127.0.0.1:5000/Electrical/Diploma/MAD1
    ```
  3. question figure
    text
    ```
    http://127.0.0.1:5000/student?dept=Electrical&level=Diploma&course=MAD1
    ```
  4. question figure
    text
    ```
    http://127.0.0.1:5000?endpoint=student&dept=Electrical&level=Diploma&course=MAD1
    ```
Q5MCQ3 marks
question figure
Text of the picture (copyable)
What will be the output of the following Python code snippet on the terminal?

```python
def modify(n):
    def modifier(n):
        ser = [0,1]
        for i in range(n-2):
            new = ser[i]+ser[i+1]
            ser.append(new)
        print(ser)
    return modifier

@modify
def list_num(n):
    nums = []
    for i in range(n):
        nums.append(i+1)
    print(nums)

list_num(10)
```
  1. question figure
    text
    ```
    [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
    ```
  2. question figure
    text
    ```
    [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
    ```
  3. question figure
    text
    ```
    [0, 1, 1, 2, 3, 5, 8, 13, 21]
    ```
  4. question figure
    text
    ```
    [0, 1, 1, 2, 3, 5, 8, 13, 21, 34]
    ```
Q6MCQ3 marks
question figure
Text of the picture (copyable)
Consider the following HTML Document file given below.
index.html

```html
<!DOCTYPE html>
<html lang="en">
<head>
    <title>Document</title>
    <style>
        input:invalid {
            background: red;
        }
        input:valid {
            background: green;
        }
    </style>
</head>
<body>
    <form>
        <label for="uname">Enter a valid e-mail:</label>
        <input type="text" name="uname" minlength="8">
    </form>
</body>
</html>
```

Suppose the index.html is rendered on the browser. What will be the background color of the input box when the user enters the name "madcourse.mail.com"?
  1. red
  2. white
  3. green
  4. insufficient information
Q7MCQ3 marks
question figure
Text of the picture (copyable)
Consider the following Python code snippet.

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

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

class MyApi(Resource):
    def get(self):
        return {"greet":"Hello from GET Api!"}

    def put(self):
        return {"greet":"Hello from PUT Api!"}

api.add_resource(MyApi, '/api/get', '/api/put', '/api/post')

app.run()
```

If this application is running locally on http://127.0.0.1:5000, which of the following curl commands will throw an error?

1. `curl http://127.0.0.1:5000/api/get -X get`
2. `curl http://127.0.0.1:5000/api/put -X put`
3. `curl http://127.0.0.1:5000/api/post -X post`
4. `curl http://127.0.0.1:5000/api/get -X put`
5. `curl http://127.0.0.1:5000/api/put -X get`
6. `curl http://127.0.0.1:5000/api/post -X get`
  1. Only 3
  2. Only 3 and 4
  3. Only 5 and 6
  4. Only 3, 4, 5 and 6
Q8MCQ3 marks
question figure
Text of the picture (copyable)
Consider the following code.

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

@app.route('/')
def generate1():
    return "This is generate1"

@app.route('//')
def generate2():
    return "This is generate2"

@app.errorhandler(404)
def page_not_found(e):
    # setting 404 status explicitly
    return 'page not found'

app.run()
```

If the flask application is running on http://127.0.0.1:5000, what will browser render for URL http://127.0.0.1:5000//
  1. Page not found
  2. This is generate2
  3. This is generate1
  4. Code will throw error
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 parent can have multiple children 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 Parent(Base):
    __tablename__ = "parent_table"
    id = Column(Integer, primary_key=True)
    # write your code 1 here

class Child(Base):
    __tablename__ = "child_table"
    id = Column(Integer, primary_key=True)
    # write your code 2 here
```
  1. question figure
    text
    ```python
    code 1: parent_id=Column(Integer, ForeignKey("child_table.id"))
    code 2: children = relationship("Parent")
    ```
  2. question figure
    text
    ```python
    code 1: children = relationship("Child")
    code 2: parent_id=Column(Integer, ForeignKey("parent_table.id"))
    ```
  3. question figure
    text
    ```python
    code 1: parent_id=Column(Integer, ForeignKey("parent_table.id"))
    code 2: children = relationship("Child")
    ```
  4. question figure
    text
    ```python
    code 1: children = relationship("Parent")
    code 2: parent_id=Column(Integer, ForeignKey("child_table.id"))
    ```
Q10MCQ4.5 marks
question figure
Text of the picture (copyable)
Consider the following models Brand and Cellphone corresponding to tables brand and cellphone in SQLite database.

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

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

Based on the model schemas, what relationship do the classes Brand and Cellphone share?
  1. One-to-One
  2. One-to-Many
  3. Many-to-Many
  4. The tables are not at all related
Q11MCQ4.5 marks
question figure
Text of the picture (copyable)
Consider the schema for the Class Student.

```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?

```
>>> s1 = Student(roll_number = M01, first_name = "Yash", last_name = "Raj")
>>> db.session.add(s1)
>>> s2 = Student(roll_number = M02, first_name = "Yash", last_name = "Maurya")
>>> db.session.add(s2)
>>> s3 = Student(roll_number = M03, first_name = "Ansh", last_name = "Raj")
>>> db.session.add(s3)
>>> db.session.commit()
>>> user1= Student.query.filter_by(first_name="Yash").first()
>>> user1.first_name= "Ansh"
>>> user1.last_name= "Maurya"
>>> db.session.commit()
>>> s1 = Student.query.all()
>>> for student in s1:
        print(student.first_name)
        print(student.last_name)
```
  1. question figure
    text
    Yash
    Raj
    Yash
    Maurya
    Ansh
    Raj
  2. question figure
    text
    Ansh
    Maurya
    Yash
    Maurya
    Ansh
    Raj
  3. question figure
    text
    Ansh
    Maurya
    Ansh
    Maurya
    Ansh
    Raj
  4. question figure
    text
    None
Q12MSQ4.5 marksselect all that apply
question figure
Text of the picture (copyable)
Consider the following route in the flask for a signup page and select the correct option.

```python
@app.route('/signup', methods=['GET', 'POST'])
def signup():
    if request.method == 'GET':
        return """<form action='/signup' method='POST'>
<label for='username'>Username</label>
<input type='text' name='username' required>
<label for='password'>Password</label>
<input type='text' name='password' required minlength="8">
<input type='submit' value='Submit'>
</form>
"""

    if request.method == 'POST':
        if request.form.get('username') is None:
            return redirect(url_for(signup))
        if request.form.get('password') is None:
            return redirect(url_for(signup))
        if len(request.form.get('password')) < 8:
            return redirect(url_for(signup))
        return f"<h1>Welcome, {request.form.get('username')}!</h1>"
```
  1. The signup page is dynamically generated.
  2. The signup page uses server-side rendering.
  3. The signup page uses frontend validation only.
  4. The signup page uses backend validation.
Q13MSQ4.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('/home')
def index():
    return 'Mad-I welcomes you!'

@app.route('/user/<username>')
def profile(username):
    return f'{username}\'s profile'

with app.test_request_context():
    #== print statement ==#
```
  1. question figure
    text
    If `print statement` is replaced by `print(url_for('home'))`,
    the output on the terminal will be Mad-I welcomes you!.
  2. question figure
    text
    If `print statement` is replaced by `print(url_for('profile', username='Harry'))`, the output on the terminal will be `/user/Harry`
  3. question figure
    text
    If `print statement` is replaced by `print(url_for('profile', username='Harry', next='course'))`, the output on the terminal will be
    `/user/Harry/course`
  4. question figure
    text
    If `print statement` is replaced by `print(url_for('index', username='Harry'))`, the output on the terminal will be
    `/home?username=Harry`
Q14MSQ3 marksselect all that apply
Which of the following is/are valid JSON format.
  1. question figure
    text
    ```json
    {
      "Age": 27,
      "firstName": "John",
      "lastName": "Pollard",
      "married": false,
      "phone_numbers": ["212-555-1234", "212-666-5678"]
    }
    ```
  2. question figure
    text
    ```json
    {
      "RollNumber": 11,
      "firstName": "Nick",
      "lastName": "Paul",
      "phone_numbers": [2125551234, "2124441234"]
    }
    ```
  3. question figure
    text
    ```json
    {
      "firstName": "Will",
      "lastName": "Smith",
      "address": [
        {
          "addressLine": "Lake Union Hill Way",
          "city": "Atlanta",
          "zipCode": 50005
        }
      ]
    }
    ```
  4. question figure
    text
    ```json
    {
      "firstName": "Hannah",
      "lastName": "Smith",
      "cities": ["Dallas", "San Antonio", "Irving"],
      "phone_numbers": ["212-555-1234", "212-666-5678"]
    }
    ```
Q15MSQ3 marksselect all that apply
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 out():
    val = request.args

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

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

If this flask app is running locally on http://localhost:5000, then which of the following statements is/are correct?
  1. question figure
    text
    For URL: http://localhost:5000/?num=abc
    Output is: **Invalid number**
  2. question figure
    text
    For URL: http://localhost:5000/?num=abc
    Output is: **Enter a valid number**
  3. question figure
    text
    For URL: http://localhost:5000/?num=
    Output is: **Invalid number**
  4. question figure
    text
    For URL: http://localhost:5000/?num=12
    Output is: **The output is 1212**
Q16SA3 marks
question figure
Text of the picture (copyable)
Consider the following flask application.

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

@app.route('/admin')
def hello_admin():
    return 'Hello Admin'

@app.route('/guest/<guest>')
def hello_guest(guest):
    return 'Hello ' +guest+ ' as Guest'

@app.route('/user/<name>')
def hello_user(name):
    if name == 'admin':
        return redirect(url_for('hello_admin'))
    else:
        return redirect(url_for('hello_guest', guest = name))

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

If this flask app is running locally on http://localhost:5000, what is the output for the following URL?
For input: http://localhost:5000/user/admin?guest=appdev1

Answer key

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