uiz Space

September 2024 term · Modern Application Development I · BSCS2003

Modern Application Development I End Term: 22 December 2024 (September 2024 term)

The IIT Madras BS Modern Application Development I (MAD 1) End Term paper sat on 22 Dec 2024, in the September 2024 term: 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
7
Numerical
2

Updated

Official paper: IIT M FOUNDATION DIPLOMA FN EXAM QDF1 22 Dec 2024 · No negative marking.

Question 1

+2 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(), unique = True, db.ForeignKey("section.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

  • D

    The tables are not at all related

Question 2

+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 %}
<h3>This is from home.html</h3>
{% endblock %}

base.html

html
<!DOCTYPE html>
<html lang="en">
<head>
<title>Document</title>
</head>
<body>
<h3 style="color: blue;"> This is from base.html </h3>
{% 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 3

+2 marksOne correct option

Consider the following Python code snippet.

python
from string import Template
sentence = Template("A $var1 fox $var2 over the $var3 dog")
output = sentence.safe_substitute(word_dict)
print(output)

Which of the following options correctly represent(s) the dictionary word_dict, such that the code does not throw any error when run in the terminal?

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

Correct answer

  • D

Question 4

+2 marksOne correct option

Which of the following is a time series database?

  1. A

    MongoDB

  2. B

    InfluxDB

  3. C

    MySQL

  4. D

    PostgreSQL

Show answer

Correct answer

  • B

    InfluxDB

Question 5

+2 marksOne correct option

Match the platforms given in column A with their correct features in column B.

  1. A

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

  2. B

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

  3. C

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

  4. D

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

Show answer

Correct answer

  • C

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

Question 6

+3 marksOne correct option

Consider the following view function.

python
from flask import Flask, request
app = Flask(__name__)
@app.route('/employee', methods=['GET', 'POST'])
def show_info():
info = request.args
details = {
'Department': info['dept'],
'ID': info['id'],
'Role': info['role']
}
return details
app.run()

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

Correct answer

  • C

Question 7

+3 marksOne correct option
  1. A

    1.35

  2. B

    2.7

  3. C

    3.15

  4. D

    5.4

Show answer

Correct answer

  • C

    3.15

Question 8

+3 marksOne correct option

Consider the following function to be tested and test functions given in the Python code snippet below.

file.py

python
def sample_function(x):
var = []
for i in range(x):
var.append((i)**3)
return var
def test_func1():
assert 125 in sample_function(6)
def test_func2():
assert 64 in sample_function(8)
def sample_test3():
assert 125 in sample_function(5)

What will be the summary of the output for the command pytest file.py on the terminal?

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

Correct answer

  • D

Question 9

+3 marksOne correct option

Consider the following HTML document.

html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script>
function makeBold(){
//MISSING JS CODE
}
</script>
</head>
<body>
Enter your name : <input type="text" id="txt1" name="txt1">
<br>
<input type="button" onclick="makeBold();" value="Click Me">
</body>
</html>

Replace the MISSING JS CODE part with the correct JS code that will change the text box content to bold?

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

Correct answer

  • D

Question 10

+3 marksOne correct option

Match the following terms with their correct descriptions:

  1. A

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

  2. B

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

  3. C

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

  4. D

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

Show answer

Correct answer

  • A

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

Question 11

+3 marksOne correct option

Which of the following is an example of an application using Attribute-Based Access Control (ABAC)?

  1. A

    A system where users are granted access based on their job roles within an organization.

  2. B

    A cloud service that grants or restricts access to files based on attributes such as user department, job title, or current location.

  3. C

    A file-sharing system where the file owner decides who can access their documents.

  4. D

    A system that enforces access based on security classifications and clearance levels.

Show answer

Correct answer

  • B

    A cloud service that grants or restricts access to files based on attributes such as user department, job title, or current location.

Question 12

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

Correct answer

  • D

Question 13

+3 marksOne correct option

Consider the following Python code snippet.

python
from math import factorial
def prettify(func):
def wrapper(num):
try:
return func(num)
except:
return "Please check your number!"
return wrapper
@prettify
def fact(num):
return factorial(num)
out = fact(5)
print(out)

What will the output if the above Python code is run on the terminal?

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

Correct answer

  • B

Question 14

+4.5 marksOne correct option

Consider the following Python code snippet.

file.py

python
from string import Template as makeTemplate
from jinja2 import Template
import sys
var = sys.argv[2]
data = {"name": "Alice", "activity": "data analysis",
"tool": "Python", "goal": "insights"}
temp = "{{name}} performs $activity using $tool to gain {{goal}}."
if var == "python":
temp = makeTemplate(temp)
out = temp.substitute(data)
output = Template(out)
output = output.render(data)
print(output)
else:
temp = Template(temp)
output = temp.render(data)
print(output)

What will be printed on the terminal for the command python file.py ml python ?

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

Correct answer

  • C

Question 15

+4.5 marksOne correct option

Consider the following HTML document.

html
<!DOCTYPE html>
<html lang="en">
<head>
<title>Document</title>
<style>
p {
background-color: yellow;
color: red;
display: inline-block;
}
#id {
border: 2px solid purple;
color:blue ;
}
.class1 {
background-color: aqua;
color: red;
}
.class2{
background-color: lightgreen;
color: darkgreen;
}
</style>
</head>
<body>
<p class="class1" id="id">Code 1</p>
<p class="class1 class2" >Code 2</p>
<p class="class1">Code 3</p>
<p >Code 4</p>
</body>
</html>

How will the browser render above HTML file?

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

Correct answer

  • D

Question 16

+4.5 marksOne correct option

Refer to the project with three files: conftest1.py, test_multiples_of_3_and_6.py, and test_multiples_of_13.py.

The purpose of the tests is to verify if numbers generated by each function are divisible by 39. However, there is a setup issue in this project.

  • conftest1.py contains a fixture that provides test data.
  • test_multiples_of_3_and_6.py has two functions: one checks divisibility by 3, and the other by 6.
  • test_multiples_of_13.py contains a function to check divisibility by 13.

Here is the content of each file:

conftest1.py

python
import pytest
@pytest.fixture
def divisible_by_39():
return 39 # Fixture providing the number to be tested

test_multiples_of_3_and_6.py

python
import pytest
def test_divisible_by_3(divisible_by_39):
assert divisible_by_39 % 3 == 0 # Checks if divisible by 3
def test_divisible_by_6(divisible_by_39):
assert divisible_by_39 % 6 == 0 # Checks if divisible by 6

test_multiples_of_13.py

python
import pytest
def test_divisible_by_13(divisible_by_39):
assert divisible_by_39 % 13 == 0 # Checks if divisible by 13

When you run pytest -k divisible , which of the following is true?

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

Correct answer

  • D

Question 17

+4.5 marksOne correct option

Consider the following Python code snippet that returns the potential energy stored in an object of a certain mass at a certain height. (PE = mgh, where “g” is acceleration due to gravity).

python
from jinja2 import Template
x = Template(template)

What should be the value of template if;

print(x.render(mass = "5", height = "22")) returns 1100 and
print(x.render()) returns 3000

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

Correct answer

  • A

Question 18

+4.5 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('/products')
def products():
return 'Product List'
@app.route('/product/<int:product_id>/<string:name>')
def product_detail(product_id, name):
return f'Product ID: {product_id}, Name: {name}'
with app.test_request_context():
#== print statement ==#

Select all that apply.

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

Correct answers

  • A
  • C

Question 19

+3 marksOne or more correct options

Consider the following code snippet.

python
from flask import Flask
import logging
app = Flask(__name__)
logging.basicConfig(filename='logger.log', level=logging.INFO,
format=f'%(asctime)s : %(message)s')
@app.route('/home')
def home():
app.logger.debug('This is a debug log')
app.logger.warning('This is a warning log')
return f"Application Dashboard"
if __name__ == "__main__":
app.run()

Suppose the given flask application is running locally on http://127.0.0.1:5000, which of the following statements is/are true if you hit the URL http://127.0.0.1:5000/home ?

Select all that apply.

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

Correct answers

  • A
  • D

Question 20

+3 marksOne or more correct options

Consider the following flask application running on the base URL and is accessed through a browser. Select the correct option(s).

python
app = Flask(__name__)
users = {
1 : {"Name": "Mukesh", "role": "Admin", "access": True},
2 : {"Name": "Gautam", "role": "User", "access": True},
3 : {"Name": "Narendra", "role": "Admin", "access": True},
4 : {"Name": "Amit", "role": "User", "access": False}
}
@app.route('/login')
def auth():
cred = request.args
if users[int(cred["id"])].get("access"):
id = int(cred["id"])
user = users[id]
return "Welcome, "+ user.get("Name")+", you have "+user.get("role")
+ " access"
else:
abort(403)
@app.errorhandler(403)
def no_access(error):
return "You are an unauthorized user!"
app.run(debug = True)

Select all that apply.

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

Correct answers

  • B
  • D

Question 21

+3 marksOne or more correct options

Consider the following Python code snippet.

File name: main.py

python
import sys
def func1(x):
return x > 0
def func2(x):
return x % 2 == 0
def test_fun3(x):
assert func1(x) == True, str(x) + " is not even/odd"
assert func2(x) == True, str(x) + " is even number"
assert x % 2 != 0, str(x) + " is odd number"
x = int(sys.argv[1])
test_fun3(x)

Which of the following is the correct combinations of “command line argument” and “assertion error”?

Select all that apply.

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

Correct answers

  • A
  • B
  • C

Question 22

+3 marksOne or more correct options

Which of the following statements about the Constraint Validation API is/are true?

Select all that apply.

  1. A

    The Constraint Validation API ensures that form input meets client-side validation rules before submission.

  2. B

    The Constraint Validation API is sufficient to prevent server-side attacks like SQL injection.

  3. C

    It is possible to bypass the Constraint Validation API by directly sending requests to the server.

  4. D

    The Constraint Validation API automatically validates all data on the server side.

Show answer

Correct answers

  • A

    The Constraint Validation API ensures that form input meets client-side validation rules before submission.

  • C

    It is possible to bypass the Constraint Validation API by directly sending requests to the server.

Question 23

+2 marksOne or more correct options

Which of the following statements is invalid in the context of the primary key?

Select all that apply.

  1. A

    The primary key can be null

  2. B

    The primary key can be auto-incremented

  3. C

    The primary key allows duplicate values

  4. D

    The primary key can be referenced by foreign keys in other tables.

Show answer

Correct answers

  • A

    The primary key can be null

  • C

    The primary key allows duplicate values

Question 24

+2 marksOne or more correct options

Consider the following HTML document.

html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>IITM</title>
</head>
<body>
<h2>Welcome to IITM </h2>
<h3>Online Degree</h3>
Courses offered
<ol>
<li>Foundation</li>
<ul>
<li>CT</li>
<li>Python</li>
<li>Maths-I</li>
</ul>
<li>Diploma</li>
<ul>
<li>PDSA</li>
<li>MAD-I</li>
<li>MAD-II</li>
</ul>
</ol>
</body>
</html>

Which of the following statements is/are correct about the above code snippet?

Select all that apply.

  1. A

    List Items, Foundations and Diploma are numbered 1 and 2

  2. B

    List Items, Foundations and Diploma are bulleted

  3. C

    List Items, PDSA, MAD-I and MAD-II are numbered 1, 2 and 3

  4. D

    List Items, PDSA, MAD-I and MAD-II are bulleted

Show answer

Correct answers

  • A

    List Items, Foundations and Diploma are numbered 1 and 2

  • D

    List Items, PDSA, MAD-I and MAD-II are bulleted

Question 25

+3 marksNumerical answer
Show answer

Correct answer: 1000

Question 26

+3 marksNumerical answer
Show answer

Correct answer: 150000

Question 27

+3 marksOne correct option

Consider the following Python flask code running on the url http://127.0.0.1:5000.

python
from flask import Flask
app = Flask(__name__)
movies = {
"Spider man1": ["action", 5, "Sam Raimi"],
"Batman": ["action", 3, "Matt Reeves"],
"Joker": ["thriller", 4, "Todd Philips"],
"Ted": ["comedy", 3, "Seth MacFarlane"],
}
def doSomething(g):
l = []
for key in movies:
if movies[key][0] == g:
l.append(key)
return l
@app.route("/<genre>")
def home(genre):
return doSomething(genre)
if __name__ == "__main__":
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

Question 28

+2 marksOne correct option

Consider the following Python flask code running on the url http://127.0.0.1:5000.

python
from flask import Flask
app = Flask(__name__)
movies = {
"Spider man1": ["action", 5, "Sam Raimi"],
"Batman": ["action", 3, "Matt Reeves"],
"Joker": ["thriller", 4, "Todd Philips"],
"Ted": ["comedy", 3, "Seth MacFarlane"],
}
def doSomething(g):
l = []
for key in movies:
if movies[key][0] == g:
l.append(key)
return l
@app.route("/<genre>")
def home(genre):
return doSomething(genre)
if __name__ == "__main__":
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

  • B

Question 29

+4.5 marksOne correct option

Consider the below Python flask code and answer the given subquestions if the app is running on “http://127.0.0.1:5000/”

File: app.py

python
app = Flask(__name__)
api = Api(app)
accounts_data = {
"sb101": {"name": "Raj", "balance": 5600},
"ca101": {"name": "David", "balance": 7600},
"fd101": {"name": "Jack", "balance": 71600},
"sb103": {"name": "Syam", "balance": 9600},
}
p = reqparse.RequestParser()
p.add_argument("balance")
class Error(HTTPException):
def __init__(self, status, error):
self.response = make_response({"Error": error}, status)
class Accounts(Resource):
def get(self, id):
if id in accounts_data:
acct = accounts_data[id]
return acct
else:
error = "Sorry, account no. " + id + " does not exist!"
raise Error(404, error)
def put(self, id):
args = p.parse_args()
if id in accounts_data:
accounts_data[id]["balance"] = args["balance"]
return accounts_data[id]
else:
error = "Account no. " + id + " does not exist and balance not
updated..."
raise Error(404, error)
api.add_resource(Accounts, "/api/get_account/<id>", "/api/update_balance/<id>")
app.run(debug=True)
  1. A
  2. B
  3. C
  4. D
Show answer

Correct answer

  • A

Question 30

+4.5 marksOne correct option

Consider the below Python flask code and answer the given subquestions if the app is running on “http://127.0.0.1:5000/”

File: app.py

python
app = Flask(__name__)
api = Api(app)
accounts_data = {
"sb101": {"name": "Raj", "balance": 5600},
"ca101": {"name": "David", "balance": 7600},
"fd101": {"name": "Jack", "balance": 71600},
"sb103": {"name": "Syam", "balance": 9600},
}
p = reqparse.RequestParser()
p.add_argument("balance")
class Error(HTTPException):
def __init__(self, status, error):
self.response = make_response({"Error": error}, status)
class Accounts(Resource):
def get(self, id):
if id in accounts_data:
acct = accounts_data[id]
return acct
else:
error = "Sorry, account no. " + id + " does not exist!"
raise Error(404, error)
def put(self, id):
args = p.parse_args()
if id in accounts_data:
accounts_data[id]["balance"] = args["balance"]
return accounts_data[id]
else:
error = "Account no. " + id + " does not exist and balance not
updated..."
raise Error(404, error)
api.add_resource(Accounts, "/api/get_account/<id>", "/api/update_balance/<id>")
app.run(debug=True)
  1. A
  2. B
  3. C
  4. D
Show answer

Correct answer

  • D

Question 31

+4.5 marksOne correct option

Use the Python code given below for answering the subquestions:

python
from flask import Flask, jsonify, request, make_response
from flask_restful import Api, Resource
app = Flask(__name__)
api = Api(app)
items = []
class Item(Resource):
def get(self, name):
item = None
for i in items:
if i['name'] == name:
item = i
break
return make_response(jsonify(item) if item else ('', 404))
def post(self, name):
# Check if item already exists
item_exists = False
for i in items:
if i['name'] == name:
item_exists = True
break
if item_exists:
return make_response(jsonify({'message': 'Item already exists'}),
400)
data = request.get_json()
new_item = {'name': name, 'price': data['price']}
items.append(new_item)
return make_response(jsonify(new_item), 201)
api.add_resource(Item, '/item/<string:name>')
if __name__ == '__main__':
app.run(debug=True)
  1. A
  2. B
  3. C
  4. D
Show answer

Correct answer

  • B

Question 32

+3 marksOne correct option

Use the Python code given below for answering the subquestions:

python
from flask import Flask, jsonify, request, make_response
from flask_restful import Api, Resource
app = Flask(__name__)
api = Api(app)
items = []
class Item(Resource):
def get(self, name):
item = None
for i in items:
if i['name'] == name:
item = i
break
return make_response(jsonify(item) if item else ('', 404))
def post(self, name):
# Check if item already exists
item_exists = False
for i in items:
if i['name'] == name:
item_exists = True
break
if item_exists:
return make_response(jsonify({'message': 'Item already exists'}),
400)
data = request.get_json()
new_item = {'name': name, 'price': data['price']}
items.append(new_item)
return make_response(jsonify(new_item), 201)
api.add_resource(Item, '/item/<string:name>')
if __name__ == '__main__':
app.run(debug=True)
  1. A

    201

  2. B

    404

  3. C

    500

  4. D

    None of these

Show answer

Correct answer

  • D

    None of these