uiz Space

May 2024 term · Modern Application Development I · BSCS2003

Modern Application Development I End Term: 1 September 2024, Set QDF1 (May 2024 term)

The IIT Madras BS Modern Application Development I (MAD 1) End Term paper sat on 1 Sept 2024, in the May 2024 term, set QDF1: 32 questions for 100 marks in 180 minutes. Every question is below with its answer. Take it as a timed mock test to be marked, or read it through first.

Questions
32
Marks
100
Duration
180 min
MCQ
23
MSQ
9

Updated

Official paper: IIT M FOUNDATION DIPLOMA AN EXAM QDF3 01 Sep 2024 · No negative marking.

Question 1

+3 marksOne correct option

Consider the following Python code snippet.

  1. A

    a - 4, b - 1, c - 6

  2. B

    a - 5, b - 3, c - 6

  3. C

    a - 5, b - 1, c - 2

  4. D

    a - 5, b - 3, c - 2

Show answer

Correct answer

  • D

    a - 5, b - 3, c - 2

Question 2

+3 marksOne correct option

Consider the following HTML document.

html
<!DOCTYPE html>
<html>
<head>
<style>
span {
background-color: yellow;
color: red;
}
#id {
border: 2px solid purple;
color:blue ;
display: inline-block;
}
.class {
background-color: aqua;
color: red;
display: block;
width:20%;
}
</style>
</head>
<body>
<span class="class" id="id">SPAN</span>
<span class="class" >SPAN</span>
<span>SPAN</span>
</body>
</html>

How will the browser render above HTML file?

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

Correct answer

  • D

Question 3

+3 marksOne correct option

Consider the following flask application.

  1. A

    1-c, 2-a, 3-b

  2. B

    1-c, 2-a, 3-d

  3. C

    1-c, 2-e, 3-d

  4. D

    1-c, 2-a, 3-e

Show answer

Correct answer

  • C

    1-c, 2-e, 3-d

Question 4

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

Correct answer

  • D

Question 5

+3 marksOne correct option

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

Correct answer

  • C

Question 6

+3 marksOne correct option

The lens of an HDD can read data on the rotating disk with the speed of 42,000 bits per second. The disk is designed such that 600 bits pass under the lens for every revolution of the disk, what should be the maximum speed of disk in RPM so that the lens does not miss any data?

  1. A

    70 RPM

  2. B

    100 RPM

  3. C

    4200 RPM

  4. D

    6000 RPM

Show answer

Correct answer

  • C

    4200 RPM

Question 7

+3 marksOne correct option

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 also all required modules are installed. Which of the below statement(s) are True?

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

    Only statement i is correct

  2. B

    Only statement ii is correct

  3. C

    Statements i and iii are correct

  4. D

    Statements ii and iv are correct

Show answer

Correct answer

  • A

    Only statement i is correct

Question 8

+3 marksOne correct option

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

Correct answer

  • C

Question 9

+3 marksOne correct option

A flask application shown below is running locally on http://127.0.0.1:5000.

python
from flask import Flask, request, session, abort
app = Flask(__name__)
app.config['SECRET_KEY'] = "yekterces"
@app.route('/login')
def log_in():
user = request.args['user']
role = request.args['role'] if 'role' in request.args else
'general'
session['user'], session['role'] = user, role
return "Logged in successfully!"
@app.route('/home')
def land():
if 'user' in session:
if session['role'] == 'admin':
return f"Welcome {session['user']}"
return abort(401)
return abort(404)
@app.route('/logout')
def log_out():
session.pop('user', None)
session.pop('role', None)
return "Logged out sucessfully!"
app.run(debug=True)

If the application is running locally on http://127.0.0.1:5000, What will be the correct sequence of response status codes if the client visits the URLs one by one in the sequence given below?

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

Correct answer

  • C

Question 10

+3 marksOne correct option

Consider the following flask application.

Python file: app.py

python
from flask import Flask, render_template, request
app = Flask(__name__)
emp = {'admin':'manoj', 'user':'sumit'}
@app.route('/profile/<user>')
def profile(user):
access = request.args.get('access')
if emp[access] != user:
return render_template("profile.html", user = user,
access = access, error = True)
return render_template("profile.html", user = user,
access = access, error = False)
app.run()

Template file: profile.html

html
<body>
<div>
{% if error %}
<h3>Hi {{user}}, {{access}} access denied</h3>
{% else %}
<h3>Hi {{user}}, you are logged in as {{access}}.</h3>
{% endif %}
</div>
</body>

If the application is running locally on http://127.0.0.1:5000, then what will be rendered by the browser for URL,
http://127.0.0.1:5000/profile/sumit?access=admin ?

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

Correct answer

  • C

Question 11

+3 marksOne correct option

Consider the following models Library and Book corresponding to tables library and book in SQLite database.

python
class Library(db.Model):
id = db.Column(db.Integer(), primary_key = True)
name = db.Column(db.String(), unique = True)
class Book(db.Model):
id = db.Column(db.Integer(), primary_key = True)
name = db.Column(db.String(), unique = True)
library = db.Column(db.Integer(), db.ForeignKey("library.id"))

Based on the model schemas, what relationship do the classes Library and Book share?

  1. A

    Many-to-Many

  2. B

    One-to-Many

  3. C

    One-to-One

  4. D

    The tables are not at all related

Show answer

Correct answer

  • B

    One-to-Many

Question 12

+3 marksOne correct option

Read the statements given below carefully and select the correct option.
Statement 1:If an element having an ID and a class is styled externally using both its ID and the class, then for the same attribute, it will acquire styling from the latest selector in order. Statement 2: If an element that belongs to two different classes is styled externally using both the classes, then for the same attribute, it will acquire styling from the latest class in order.

  1. A

    Both statements 1 and 2 are correct

  2. B

    Both statements 1 and 2 are incorrect

  3. C

    Statement 1 is correct but statement 2 is incorrect

  4. D

    Statement 2 is correct but statement 1 is incorrect

Show answer

Correct answer

  • D

    Statement 2 is correct but statement 1 is incorrect

Question 13

+4.5 marksOne correct option

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

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

Correct answer

  • D

Question 14

+4.5 marksOne correct option

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?

  1. A

    633.6 GB

  2. B

    54 GB

  3. C

    120 GB

  4. D

    432 GB

Show answer

Correct answer

  • B

    54 GB

Question 15

+4.5 marksOne correct option

Consider the below flask application.

python
from flask_sqlalchemy import SQLAlchemy
from flask import Flask
app = Flask (__name__)
app.config ['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///testdb.sqlite3'
db = SQLAlchemy(app)
app.app_context().push()
class Material(db.Model):
m_id = db.Column('m_id', db.Integer, primary_key = True)
name = db.Column('name', db.String(100), unique = True)
db.create_all()
material1 = Material(name = 'Steel')
db.session.add(material1)
material2 = Material(name = 'Iron')
material3 = Material(name = 'Aluminium')
db.session.add(material2)
db.session.commit()
db.session.add(material3)
all_material = Material.query.all()
print([(x.m_id, x.name) for x in all_material])

If you run the flask application using a terminal. What will be the output in the terminal?

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

Correct answer

  • C

Question 16

+4.5 marksOne correct option
  1. A

    45

  2. B

    90

  3. C

    180

  4. D

    270

Show answer

Correct answer

  • C

    180

Question 17

+2 marksOne correct option

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

Correct answer

  • C

Question 18

+2 marksOne correct option
  1. A

    A → 1, B → 2, C → 3, D → 4

  2. B

    A → 4, B → 3, C → 2, D → 1

  3. C

    A → 4, B → 1, C → 2, D → 3

  4. D

    A → 3, B → 2, C → 1, D → 4

Show answer

Correct answer

  • C

    A → 4, B → 1, C → 2, D → 3

Question 19

+2 marksOne correct option

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>
<p>DBMS</p>
{% 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. A
  2. B
  3. C
  4. D
Show answer

Correct answer

  • B

Question 20

+2 marksOne correct option

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

    16

  2. B

    8

  3. C

    32

  4. D

    128

Show answer

Correct answer

  • C

    32

Question 21

+2 marksOne correct option
  1. A

    AC0A FE01

  2. B

    CA10 EF0A

  3. C

    AC01 0AEF

  4. D

    AC10 FE0A

Show answer

Correct answer

  • D

    AC10 FE0A

Question 22

+2 marksOne correct option

Which of the following is true about the term “stateless” in the client-server model?

  1. A

    The server keeps the state of the client to respond to the required request.

  2. B

    Server use variant HTTP methods to respond to the client's request.

  3. C

    Server ready to respond to the client's request without knowing anything about the client.

  4. D

    Server use the URL to convey context to the client.

Show answer

Correct answer

  • C

    Server ready to respond to the client's request without knowing anything about the client.

Question 23

+2 marksOne or more correct options

Consider the following Python code snippet “code.py”.

Filename: code.py

python
import sys
from jinja2 import Template
vars = sys.argv
course_technologies = {'python': 'backend', 'javascript': 'frontend'}
template = Template("This course focuses on {{ technology }} development.")
if len(vars) > 2 and vars[2] in course_technologies:
course = vars[1]
technology = course_technologies[course]
print(template.render(technology=technology))
else:
print("Please specify a valid course name!")

Which of the following will be the correct command line input to the terminal to get the output : This course focuses on backend development. ?

Select all that apply.

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

Correct answers

  • B
  • C

Question 24

+2 marksOne or more correct options

Consider the following flask application.

app.py

python
from flask import Flask, abort, request
app = Flask(__name__)
data = {"CS2001":"DBMS","CS2003":"MAD-I","CS2006":"MAD-II"}
@app.route('/login')
def login():
username = request.args.get('uname')
if username not in data:
abort(400, "Bad Request: Invalid Username")
return f'<h1>Welcome to {data[username]} course!</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

  • C
  • D

Question 25

+3 marksOne or more correct options

Consider the following flask application.

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 "Hello from GET method"
elif var_a == "POST":
return "Hello from POST method"
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?

Select all that apply.

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

Correct answers

  • A
  • B

Question 26

+3 marksOne or more correct options

Consider the following flask_sqlalchemy data models “User” and “Role”.

python
class User(db.Model):
id = db.Column(db.Integer, primary_key=True)
username= db.Column(db.String(), unique=True, nullable=False)
password = db.Column(db.String(), nullable=False)
email= db.Column(db.String())
roles= db.relationship("Role", backref="bearer")
class Role(db.Model):
id = db.Column(db.Integer, primary_key=True)
r_name = db.Column(db.String(), unique=True, nullable=False)
user = db.Column(db.Integer, db.ForeignKey("user.id"))

python shell:

python
>>> from app import *
>>> db.create_all()
>>> user1 = User(username="Rakesh",password="1234",email="user1@gmail.com")
>>> user2 = User(username="Suresh",password="123",email="user2@gmail.com")
>>> db.session.add_all([user1,user2])
>>> db.session.commit()
>>> r1=Role(r_name="instructor",user=1)
>>> r2=Role(r_name="admin",user=1)
>>> r3=Role(r_name="ops",user=2)
>>> r4=Role(r_name="student",user=2)
>>> db.session.add_all([r1,r2,r3,r4])
>>> db.session.commit()
>>> users = User.query.all()
>>> roles = Role.query.all()

If the above commands are run in the python shell then which of the following options is /are correct with respect to these models?

Select all that apply.

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

Correct answers

  • B
  • D
  • E

Question 27

+3 marksOne or more correct options

Suppose a request https://xyz.com?name=amey&age=34 generates the below response on the browser’s console,

text
Name : amey

The definition of the flask endpoint which handles the above request is given below,

python
@app.route(code1)
def getData():
data = code2
print("Name :", data)

Which of the following options should be used to fill the placeholders “code1” and “code2”, to achieve the desired result as shown above?

Select all that apply.

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

Correct answers

  • C
  • D

Question 28

+4.5 marksOne or more correct options

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;

text
========= 1 passed, 3 deselected, 4 warnings in 0.04s =========

What command will result into the outcome given above?

Select all that apply.

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

Correct answers

  • A
  • C

Question 29

+4.5 marksOne or more correct options

Consider the following flask application.

python
from flask import Flask, abort
app = Flask(__name__)
modules = ['python', 'react', 'node']
@app.route('/home/modules/')
def all_modules():
return f"<h3>List of modules: {modules}</h3>"
@app.route('/get/<string:module_1>')
def get_module(module_1):
if module_1 in modules:
return f"<h3>One module found: {module_1}.</h3>"
else:
abort(400)
@app.errorhandler(400)
def module_error(error):
return "<h3>Cannot find module</h3>"
@app.errorhandler(404)
def module_error(error):
return "<h3>Incorrect Path</h3>"
app.run(debug=True)

If the application is running locally on http://127.0.0.1:5000, select the correct statement(s).

Select all that apply.

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

Correct answers

  • A
  • C

Question 30

+4.5 marksOne or more correct options

Consider the following code snippet.

python
@app.route('/student/<student_id>')
def profile(student_id):
# CODE BLOCK HERE

Assume the database has a "student" table which has a TEXT column "student_id". If we want the server to return a 404 status code when a user goes to the route '/student/<student_id>' with a student_id that does not exist in the database, which of the following lines would give us the desired output?

Select all that apply.

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

Correct answers

  • A
  • C
  • D

Question 31

+4.5 marksOne or more correct options

Consider the following flask application running locally on http://127.0.0.1:5000

app.py

python
from flask import Flask, request
import sys
app = Flask(__name__)
data = ["Java", "Application Development","DBMS"]
@app.route('/course')
def home():
course = request.args.get('course')
if course in sys.argv[1]:
if sys.argv[1] in data:
return f"Welcome to {sys.argv[1]}!"
return f"Welcome to {course}!"
else:
return "Invalid Data"
app.run(debug=True)

Based on the above data, answer the given subquestions.

Select all that apply.

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

Correct answers

  • B
  • D

Question 32

+3 marksOne correct option

Consider the following flask application running locally on http://127.0.0.1:5000

app.py

python
from flask import Flask, request
import sys
app = Flask(__name__)
data = ["Java", "Application Development","DBMS"]
@app.route('/course')
def home():
course = request.args.get('course')
if course in sys.argv[1]:
if sys.argv[1] in data:
return f"Welcome to {sys.argv[1]}!"
return f"Welcome to {course}!"
else:
return "Invalid Data"
app.run(debug=True)

Based on the above data, answer the given subquestions.

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

Correct answer

  • C