Quiz Space

September 2023 term · Modern Application Development I · BSCS2003

MAD 1 Quiz 2: 3 December 2023 (September 2023 term)

The IIT Madras BS Modern Application Development I (MAD 1) Quiz 2 paper sat on 3 Dec 2023, in the September 2023 term: 16 questions for 50 marks in 120 minutes. Every question is below with its answer. Take it as a timed mock test to be marked, or read it through first.

Questions
16
Marks
50
Duration
120 min
MCQ
11
MSQ
5

Updated

Official paper: IIT M DIPLOMA AN2 EXAM QDD2 03 Dec 2023 · No negative marking.

Question 1

+4.5 marksOne correct option

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. A
  2. B
  3. C
  4. D
Show answer

Correct answer

  • B

Question 2

+4.5 marksOne correct option

Consider the following flask application.

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. A
  2. B
  3. C
  4. D
Show answer

Correct answer

  • D

Question 3

+3 marksOne or more correct options

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 ==#

Select all that apply.

  1. A
  2. B
  3. C
  4. D
Show answer

Correct answers

  • C
  • D

Question 4

+3 marksOne or more correct options

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 ?

Select all that apply.

  1. A
  2. B
  3. C
  4. D
Show answer

Correct answers

  • B
  • C

Question 5

+2 marksOne correct option

In the context of in-memory databases, what is the primary function of an index?

  1. A

    To encrypt sensitive data

  2. B

    To optimize query performance by speeding up data retrieval

  3. C

    To manage data replication

  4. D

    To store metadata about the database structure

Show answer

Correct answer

  • B

    To optimize query performance by speeding up data retrieval

Question 6

+2 marksOne correct option

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

    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. B

    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. C

    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. D

    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.

Show answer

Correct answer

  • C

    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.

Question 7

+2 marksOne correct option

In the context of API documentation, what is typically provided to describe the available endpoints, request parameters and response formats?

  1. A

    API documentation or API reference

  2. B

    API key

  3. C

    Software source code

  4. D

    OAuth tokens

Show answer

Correct answer

  • A

    API documentation or API reference

Question 8

+2 marksOne correct option

Consider the models "Channel" and "Video" used to create the tables "channel" and "video" in SQLite database using flask-sqlalchemy and answer the given subquestions.

python
class Channel(db.Model):
id = db.Column(db.Integer, primary_key = True)
name = db.Column(db.String(50), unique = True, nullable = False)
videos = db.relationship("Video", backref = "playlist")
class Video(db.Model):
id = db.Column(db.Integer, primary_key = True)
name = db.Column(db.String(50), unique = True, nullable = False)
channel = db.Column(db.Integer, db.ForeignKey("channel.id"))
  1. A

    One-to-one

  2. B

    One-to-many

  3. C

    Many-to-one

  4. D

    Many-to-many

Show answer

Correct answer

  • B

    One-to-many

Question 9

+3 marksOne or more correct options

Consider the models "Channel" and "Video" used to create the tables "channel" and "video" in SQLite database using flask-sqlalchemy and answer the given subquestions.

python
class Channel(db.Model):
id = db.Column(db.Integer, primary_key = True)
name = db.Column(db.String(50), unique = True, nullable = False)
videos = db.relationship("Video", backref = "playlist")
class Video(db.Model):
id = db.Column(db.Integer, primary_key = True)
name = db.Column(db.String(50), unique = True, nullable = False)
channel = db.Column(db.Integer, db.ForeignKey("channel.id"))

Select all that apply.

  1. A
  2. B
  3. C
  4. D
Show answer

Correct answers

  • B
  • C

Question 10

+3 marksOne correct option
  1. A
  2. B
  3. C
  4. D
Show answer

Correct answer

  • D

Question 11

+3 marksOne correct option

If the app first receives the request,

bash
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. A
  2. B
  3. C
  4. D
Show answer

Correct answer

  • C

Question 12

+3 marksOne correct option

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. A

    55 milliseconds

  2. B

    50 milliseconds

  3. C

    80 milliseconds

  4. D

    60 milliseconds

Show answer

Correct answer

  • A

    55 milliseconds

Question 13

+3 marksOne correct option

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. A

    300

  2. B

    900

  3. C

    12000

  4. D

    18000

Show answer

Correct answer

  • D

    18000

Question 14

+3 marksOne correct option

What will be the output of the following Python code snippet?

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. A
  2. B
  3. C
  4. D
Show answer

Correct answer

  • C

Question 15

+4.5 marksOne or more correct options

Consider the following flask view function defined to add a product and select correct statement(s).

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>
"""

Select all that apply.

  1. A
  2. B
  3. C
  4. D
Show answer

Correct answers

  • B
  • C
  • D

Question 16

+4.5 marksOne or more correct options

Consider the following Python code snippet.

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")

Which of the following statements is/are correct?

Select all that apply.

  1. A
  2. B
  3. C
  4. D
Show answer

Correct answers

  • C
  • D