MAD 1 End Term: 24 December 2023, Set FDD1 (September 2023 term)
The IIT Madras BS Modern Application Development I (MAD 1) End Term paper sat on 24 Dec 2023, in the September 2023 term, set FDD1: 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.
- 32
- 100
- 180 min
- 27
- 5
Show answer
Correct answer
Question 2
Read the statements given below carefully and select the correct option.
Statement 1: If an element is styled externally using two different classes and an ID, then for the same attribute, it will always acquire styling from the latest style in order.
Statement 2: If an element is styled internally using ID and class selector as well as using inline styling for the same style attribute, then it will acquire styling from the ID selector.
Both statements 1 and 2 are correct
Both statements 1 and 2 are incorrect
Statement 1 is correct but statement 2 is incorrect
Statement 2 is correct but statement 1 is incorrect
Show answer
Correct answer
Both statements 1 and 2 are incorrect
Question 3
Consider two python files, one.py and two.py with following code snippets.
File1: one.py
import sysimport twoprint(f'{sys.argv[0]} {sys.argv[1]}')File2: two.py
import sysprint(f'{sys.argv[3]} {sys.argv[2]}')What is the output of the following command “python one.py two.py one.py two.py ”?
Show answer
Correct answer
Question 4
What is the primary purpose of curl?
Web server configuration
Making requests to the web server
Database management
HTML parsing
Show answer
Correct answer
Making requests to the web server
Question 5
What is template inheritance in Jinja2 used for?
To establish a database connection
To create a new database table
To define a base template with a common structure and placeholders that can be extended by child templates
To insert CSS styles
Show answer
Correct answer
To define a base template with a common structure and placeholders that can be extended by child templates
Question 6
Which of the following is a common method to achieve data persistence in web applications?
Storing data in volatile cache
Saving data to temporary files
Writing data to a database
Using data stored in RAM
Show answer
Correct answer
Writing data to a database
Question 7
Which of the following helps us to create custom HTML elements?
SVG
Web Components
Web API
None of these
Show answer
Correct answer
Web Components
Question 8
How will the browser render the following HTML document?
<!DOCTYPE html><html><head> <title>Document</title> <style> div{ border: 1px solid black; color:pink; display: inline-block; } span{ border: 1px solid pink; } </style></head> <body> <div>Div 1</div> <div>Div 2</div> <span>Span 1</span> <span>Span 2</span> </body></html>Show answer
Correct answer
Question 9
Consider the below flask application.
from flask_sqlalchemy import SQLAlchemyfrom 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?
Show answer
Correct answer
Question 10
Consider a function func, and a set of test cases given below.
Filename: test_file.py
import pytestdef 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) == 10
def test_case3(self): assert func(4,2) == 21
class Test_class1(): def test_case1(self): assert func(5,2) == 27
def case_test2(self): assert func(4,3) == 25What will be the output on the terminal for the command below?
pytest test_file.py -k Test_classShow answer
Correct answer
Question 11
Consider the statements given below and choose the correct option.
Statement 1: 100% condition coverage automatically implies 100% branch coverage. Statement 2: 100% branch coverage automatically implies 100% condition coverage.
Both statement 1 and 2 are correct.
Both statement 1 and 2 are incorrect.
Statement 1 is correct but, statement 2 is incorrect.
Statement 2 is correct but, statement 1 is incorrect.
Show answer
Correct answer
Both statement 1 and 2 are incorrect.
Question 12
Show answer
Correct answer
Question 13
Consider the following function to be tested and test functions given in the Python code snippet below.
test_file.py
import pytest
def square(x): sum = 0 for counter in range(x): sum += x return sum
@pytest.mark.marker1def testcase_1(): assert square(12) == 144
@pytest.mark.marker2def testcase_2(): assert square(9) == 9
@pytest.mark.marker3def testcase_3(): assert square(3) == 27On running this file on the terminal using pytest, the summary of the output is;
============ 1 passed, 2 deselected, 3 warnings in 0.02s ============What command will result into the outcome given above?
Show answer
Correct answer
Question 14
AC0A FE01
CA10 EF0A
AC01 0AEF
AC10 FE0A
Show answer
Correct answer
AC10 FE0A
Question 15
Consider the following models Creator and Song corresponding to tables creator and song in SQLite database.
class Creator(db.Model): id = db.Column(db.Integer(), primary_key = True) c_name = db.Column(db.String(), unique = True)
class Song(db.Model): id = db.Column(db.Integer(), primary_key = True) s_title = db.Column(db.String(), unique = True) singer = db.Column(db.Integer(), db.ForeignKey("singer.id"))Based on the model schemas, what relationship do the table creator and song share?
Many-to-Many
One-to-Many
One-to-One
The tables are not at all related
Show answer
Correct answer
The tables are not at all related
Question 16
What is the git command to change the registered e-mail of a user using CLI?
Show answer
Correct answer
Question 17
application
__application__
main
__main__
Show answer
Correct answer
__main__
Question 18
A flask application shown below is running locally on http://127.0.0.1:5000.
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?
http://127.0.0.1:5000/homehttp://127.0.0.1:5000/login/adminhttp://127.0.0.1:5000/login?user=adminhttp://127.0.0.1:5000/homehttp://127.0.0.1:5000/logout
Show answer
Correct answer
Question 19
a - 4, b - 1, c - 2, d - 3
a - 3, b - 1, c - 4, d - 2
a - 4, b - 1, c - 3, d - 2
a - 1, b - 3, c - 2, d - 4
Show answer
Correct answer
a - 3, b - 1, c - 4, d - 2
Question 20
Show answer
Correct answer
Question 21
Consider the following function to be tested and test functions given in the Python code snippet below.
test_file.py
powers = []
for i in range(1,5): def powers_of_x(x): return x**i powers.append(powers_of_x)
powers_of_4 = [x(4) for x in powers]
def testcase_1(): assert 12 in powers_of_4
def testcase_2(): assert 64 in powers_of_4
def testcase_3(): assert 256 in powers_of_4For the command pytest test_file.py, what will be the output on the terminal?
Show answer
Correct answer
Question 22
Consider the following HTML document rendered using a browser.
<!DOCTYPE html><html lang="en"> <head> <title>Document</title> <style> input:valid { background: green; } input:invalid { background: red; } </style> </head> <body> <form> <label for="uname">Enter a valid e-mail:</label> <input type="text" name="uname" minlength="5" maxlength="8" value="a"> </form> </body></html>If a user starts typing "madcourse" letter by letter, how will the background colour of the <input> tag change?
Red for first five letters, turns green till 8th letter and turns red back again after next letter.
Green for first five letters, turns red till 8th letter and turns green back again after next letter.
Red for first five letters, and remain green after that.
Green for first five letters, and remain red after that.
Show answer
Correct answer
Red for first five letters, and remain green after that.
Question 23
Show answer
Correct answers
Question 24
Consider the following flask application.
app.py
from flask import Flaskapp = Flask(__name__)
@app.route('/home/<path:url_path>')def course(url_path): return 'The path is: ' + url_path
@app.route('/home/details/<student_id>/<course_id>')def home(student_id, course_id): return f'The student-id and course-id are {student_id} and {course_id} respectively.'
@app.route('/home/student/<student_id>/<course_id>')def details(student_id, course_id): details = {'course_id': course_id,'student_id': student_id} return details
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 ?
Show answer
Correct answers
Question 25
Consider the following python code snippet and choose the correct option.
def modify(func): def wrapper(x): list = func(x, []) return list return wrapper
@modifydef expandList(x, list = []): list.append(x) return list
print(expandList(5))print(expandList(6))Show answer
Correct answers
Question 26
Consider the following flask application.
from flask import Flask, abortapp = 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).
Show answer
Correct answers
Question 27
Consider the following flask view function definition given below.
@app.route('/login', methods=['GET', 'POST'])def login(): if request.method == 'GET': return render_template("login.html") if request.method == 'POST': #=== POST logic === return render_template("profile.html")Which of the following view function definitions would work the same as that of one given above?
Show answer
Correct answers
Question 28
What is the maximum number of requests that can be made to B per second?
166
100
56
111
Show answer
Correct answer
56
Question 29
What is the round trip time (RTT) in milliseconds for server B?
10
6
18
5
Show answer
Correct answer
6
Question 30
Consider the following resource "TestAPI" created using flask-restful which is running locally on http://127.0.0.1:5000 and answer the given subquestions.
parser = reqparse.RequestParser()parser.add_argument('movie')parser.add_argument('genre')
r_fields = {"film":fields.String(attribute = 'movie')}
class TestAPI(Resource):# =============================================# GET-FUNCTION# =============================================# =============================================# POST-FUNCTION def post(self, genre): return {'Genre': genre}# ============================================= @marshal_with(r_fields) def put(self): this_film = parser.parse_args() return this_film
api.add_resource(TestAPI, "/api/v1", "/api/v1/<genre>")If the curl request shown below.
curl http://127.0.0.1:5000/api/v1 -X GET -d "{\"movie\" : \"X-men\",\"genre\": \"Action\"}" -H "Content-Type: application/json"retrieves the movie only with status 200 OK, what will come in place of GET-FUNCTION in the code?
Show answer
Correct answer
Question 31
Consider the following resource "TestAPI" created using flask-restful which is running locally on http://127.0.0.1:5000 and answer the given subquestions.
parser = reqparse.RequestParser()parser.add_argument('movie')parser.add_argument('genre')
r_fields = {"film":fields.String(attribute = 'movie')}
class TestAPI(Resource):# =============================================# GET-FUNCTION# =============================================# =============================================# POST-FUNCTION def post(self, genre): return {'Genre': genre}# ============================================= @marshal_with(r_fields) def put(self): this_film = parser.parse_args() return this_film
api.add_resource(TestAPI, "/api/v1", "/api/v1/<genre>")Show answer
Correct answer
Question 32
Consider the following resource "TestAPI" created using flask-restful which is running locally on http://127.0.0.1:5000 and answer the given subquestions.
parser = reqparse.RequestParser()parser.add_argument('movie')parser.add_argument('genre')
r_fields = {"film":fields.String(attribute = 'movie')}
class TestAPI(Resource):# =============================================# GET-FUNCTION# =============================================# =============================================# POST-FUNCTION def post(self, genre): return {'Genre': genre}# ============================================= @marshal_with(r_fields) def put(self): this_film = parser.parse_args() return this_film
api.add_resource(TestAPI, "/api/v1", "/api/v1/<genre>")Show answer
Correct answer
