Question 1
Riya
Name stored in database
None
Error

The IIT Madras BS Modern Application Development I (MAD 1) End Term paper sat on 31 Aug 2025, in the May 2025 term, set QDB3: 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.
Riya
Name stored in database
None
Error
Correct answer
Riya
What does SQLAlchemy's lazy='dynamic' do?
Loads extra content of all the tables
Returns a query object that can be filtered
Loads all related records immediately
Forces join queries at once
Correct answer
Returns a query object that can be filtered
Why is using the GET method for sensitive data discouraged?
GET encrypts the URL
Data becomes part of browser history and URL
It uses a separate request header
Flask doesn’t support GET by default
Correct answer
Data becomes part of browser history and URL
You define two routes in your Flask app as:
@app.route('/home')def home(): return "Home No Slash"
@app.route('/about/')def about(): return "About With Slash"A user visits /about (without the trailing slash). What will Flask do?
Correct answer
A login form doesn't show any message when users enter wrong credentials. Which Nielsen heuristic is violated?
Aesthetic and minimalist design
Visibility of system status
Error prevention
Recognition rather than recall
Correct answer
Visibility of system status
Which of the following are handled by the browser and not the Flask server?
Parsing HTML
Auto-filling saved form data
URL routing
JavaScript execution
Correct answers
Parsing HTML
Auto-filling saved form data
JavaScript execution
Consider the following git branches for a remote repository.
feature1* feature2 mainChoose the correct git command sequence to merge feature1 and feature2 into the main branch.
Correct answer
Correct answer
What will be displayed when running python app.py 8080 for the following script?
app.py
import sysport = int(sys.argv[1]) if len(sys.argv) > 1 else 5000print(f"Server running on port {port}")Correct answer
Consider the following Flask code.
from flask import Flaskimport sys
app = Flask(__name__)
# Read multiplier from command-lineMULTIPLIER = int(sys.argv[1]) if len(sys.argv) > 1 else 1
@app.route('/multiply/<int:number>')def multiply(number): return f"Result: {number % MULTIPLIER}"
if __name__ == '__main__': app.run()What will be the output when you run the following code in the terminal python app.py 5 and then access in the browser with the following link http://localhost:5000/multiply/4 ?
Result: 20
Result: 1
Result: 5
Result: 4
Correct answer
Result: 4
Consider the following Python code
File name: main_test.py
import pytest
class TestGroup:
def do_something(self, x, y): return x % y
def test_one(self): assert self.do_something(10, 5) == 0, " Is 5 factor of 10? "
def test_two(self): assert self.do_something(32, 5) == 0, " Is 5 factor of 32 "What will be the output of running the above python script using command line “pytest -v main_test.py”?
Correct answer
You created the following templates:
base.html
<html><body> {% block content %}{% endblock %}</body></html>home.html
{% extends "base.html" %}<h1>Welcome!</h1>But when rendered, "Welcome!" doesn't appear. Why?
Correct answer
A user downloads a 10 MB file from a server with 5 Mbps speed. How long does it approximately take?
2 seconds
10 seconds
16 seconds
1.6 seconds
Correct answer
16 seconds
Suppose you have these models in your Flask-SQLAlchemy app:
class Author(db.Model): id = db.Column(db.Integer, primary_key=True) books = db.relationship('Book', backref='author', cascade="all, delete")
class Book(db.Model): id = db.Column(db.Integer, primary_key=True) title = db.Column(db.String(80)) author_id = db.Column(db.Integer, db.ForeignKey('author.id'))If you delete an Author instance from the database, what happens to their related Book instances?
Correct answer
Consider the following HTML code snippet (without any CSS styling).
<div> <p>This is paragraph 1</p> <span>Span element 1</span> <span>Span element 2</span> <p>This is paragraph 2</p> <a href="#">Link 1</a> <a href="#">Link 2</a> <div>Nested div content</div> <strong>Bold text</strong> <em>Italic text</em></div>Which of the following statements correctly describes how the elements will be displayed by default in a browser?
Correct answer
Consider the following Python code.
File name: main.py
def funA(func): def inner_wrapper(): print("Wrapper function of funA") res1 = func() res2 = func() return res1, res2 return inner_wrapper
@funAdef funB(): return "I am from funB"
print(funB())What will be the output, when running the above code using the command “python main.py”?
Correct answer
1-a, 2- c, 3-b, 4-d, 5-e
1-b, 2- c, 3-a, 4-e, 5-d
1-e, 2- d, 3-c, 4-a, 5-b
1-e, 2- d, 3-b, 4-a, 5-c
Correct answer
1-e, 2- d, 3-b, 4-a, 5-c
You are working on a team project hosted on GitHub. After making changes to your local files, you run the following commands in this exact order:
git statusgit add .git commit -m "Fixed header bug"git pushgit pullAssuming your teammate pushed a new change just before you did git push, what is the most likely outcome?
Correct answer
Consider the following Flask application structure and code.
my_project/├── app.py├── views/│ └── dashboard.html├── templates/│ ├── base.html│ └── home.html└── custom_templates/ ├── admin/ │ └── login.html └── user/ └── profile.htmlapp.py:
from flask import Flask, render_template
app = Flask(__name__, template_folder='custom_templates')
@app.route('/')def home(): return render_template('home.html')
@app.route('/admin')def admin_login(): return render_template('admin/login.html')
@app.route('/profile')def user_profile(): return render_template('user/profile.html')
@app.route('/dashboard')def dashboard(): return render_template('dashboard.html')
if __name__ == '__main__': app.run(debug=True)Which of the following statements about the template rendering behavior is correct?
Correct answer
Examine the following Python code snippet.
File: logger_test.py
import loggingimport sys
logging.basicConfig(level=logging.WARNING, format='%(asctime)s - %(levelname)s - %(message)s')
def process_data(num): logging.debug("Starting data processing") logging.info("Processing number: %d", num)
if num == 0: logging.warning("Zero value detected - potential division by zero") return None elif num < 0: logging.error("Negative number provided: %d", num) return None else: result = 100 / num logging.info("Calculation completed successfully") return result
try: input_num = int(sys.argv[1]) result = process_data(input_num) if result: print(f"Result: {result}")except IndexError: logging.critical("No command line argument provided")except ValueError: logging.error("Invalid input - not a number")What will be the output when running the command: python logger_test.py -5 ?
Correct answer
Consider the following Python code snippet:
python: app.py
from string import Templatefrom jinja2 import Template as JinjaTemplateimport sys
mode = sys.argv[1]data = {"user": "Bob", "language": "JavaScript", "project": "web app", "status": "completed"}
template_str = "Hello ${user}! Your {{project}} written in {{language}} is ${status}."
if mode == "hybrid": str_template = Template(template_str) intermediate = str_template.substitute(data) jinja_template = JinjaTemplate(intermediate) result = jinja_template.render(data) print(result)else: jinja_template = JinjaTemplate(template_str) result = jinja_template.render(data) print(result)What will be printed on the terminal for the command: python app.py hybrid ?
Correct answer
Consider the following Flask app code.
from flask import Flaskfrom flask_restful import Resource, Api
app = Flask(__name__)api = Api(app)
class MyApiResource(Resource): def get(self): return {"response": "GET"}, 200
def post(self, value): return {"response": "POST", "value": value}, 200
api.add_resource(MyApiResource, "/", "/<int:value>")
if __name__ == "__main__": app.run(debug=True)The above flask app is running on “http://127.0.0.1:5000”. Which of the following commands will return a runtime error?
Correct answers
Correct answers
Examine the following Python test file:
Filename: math_tests.py
import pytest
def multiply(a, b): return a * b
def divide(a, b): if b == 0: raise ValueError("Cannot divide by zero") return a / b
@pytest.mark.unitdef test_multiply_positive(): assert multiply(3, 4) == 12
@pytest.mark.integrationdef test_divide_normal(): assert divide(10, 2) == 5.0
@pytest.mark.slow@pytest.mark.integrationdef test_complex_calculation(): result = divide(multiply(6, 7), 2) assert result == 21.0@pytest.mark.unitdef test_multiply_negative(): assert multiply(-2, 3) == -6Consider the following pytest command output:
========= 1 passed, 3 deselected in 0.02s =========Which of the following pytest commands would produce the output shown above?
Correct answers
Correct answers
Consider the following Flask application.
from flask import Flask, abort, requestapp = Flask(__name__)
courses = { "IT2001": "Web Development", "IT2002": "Database Systems", "IT2003": "Software Engineering", "IT2004": "Data Structures"}
@app.route('/course')def get_course(): course_id = request.args.get('id') level = request.args.get('level', 'beginner')
if not course_id: abort(400, "Bad Request: Course ID is required")
if course_id not in courses: abort(404, "Not Found: Course does not exist") return f'<h2>{courses[course_id]} - Level: {level.title()}</h2>'
@app.route('/search')def search_courses(): query = request.args.get('q') min_length = int(request.args.get('min', 3)) if not query or len(query) < min_length: abort(422, "Unprocessable Entity: Query too short")
results = [name for name in courses.values() if query.lower() in name.lower()] if not results:
return '<p>No courses found</p>'
return f'<ul>{"".join([f"<li>{course}</li>" for course in results])}</ul>'
app.run(debug=True)Based on the above data, answer the given subquestions.
Correct answers
Consider the following Flask application.
from flask import Flask, abort, requestapp = Flask(__name__)
courses = { "IT2001": "Web Development", "IT2002": "Database Systems", "IT2003": "Software Engineering", "IT2004": "Data Structures"}
@app.route('/course')def get_course(): course_id = request.args.get('id') level = request.args.get('level', 'beginner')
if not course_id: abort(400, "Bad Request: Course ID is required")
if course_id not in courses: abort(404, "Not Found: Course does not exist") return f'<h2>{courses[course_id]} - Level: {level.title()}</h2>'
@app.route('/search')def search_courses(): query = request.args.get('q') min_length = int(request.args.get('min', 3)) if not query or len(query) < min_length: abort(422, "Unprocessable Entity: Query too short")
results = [name for name in courses.values() if query.lower() in name.lower()] if not results:
return '<p>No courses found</p>'
return f'<ul>{"".join([f"<li>{course}</li>" for course in results])}</ul>'
app.run(debug=True)Based on the above data, answer the given subquestions.
Analyze the following URLs and their expected behaviors. Which statement is CORRECT?
Correct answers
Consider the following Flask-RESTful resource class for a student management system:
class StudentResource(Resource): def get(self, student_id=None): if student_id: return {"message": "Student details", "id": student_id}, 200 return {"message": "All students"}, 200
def post(self): parser = reqparse.RequestParser() parser.add_argument('name', required=True, help='Name is required') parser.add_argument('age', type=int, required=True, help='Age is required') args = parser.parse_args() return {"message": "Student created", "data": args}, 201
def put(self, student_id): return {"message": "Student updated", "id": student_id}, 200
def delete(self, student_id): return {"message": "Student deleted", "id": student_id}, 204
class CourseResource(Resource): def get(self, course_code): return {"course": course_code, "status": "active"}, 200
def post(self, course_code, student_id): return { "message": "Student enrolled", "course": course_code, "student_id": student_id }, 201
api.add_resource(StudentResource, '/students', '/students/<int:student_id>')api.add_resource(CourseResource, '/courses/<string:course_code>', '/courses/<string:course_code>/enroll/<int:student_id>')
if __name__ == '__main__': app.run(debug=True)Based on the above data, answer the given subquestions.
Correct answer
Consider the following Flask-RESTful resource class for a student management system:
class StudentResource(Resource): def get(self, student_id=None): if student_id: return {"message": "Student details", "id": student_id}, 200 return {"message": "All students"}, 200
def post(self): parser = reqparse.RequestParser() parser.add_argument('name', required=True, help='Name is required') parser.add_argument('age', type=int, required=True, help='Age is required') args = parser.parse_args() return {"message": "Student created", "data": args}, 201
def put(self, student_id): return {"message": "Student updated", "id": student_id}, 200
def delete(self, student_id): return {"message": "Student deleted", "id": student_id}, 204
class CourseResource(Resource): def get(self, course_code): return {"course": course_code, "status": "active"}, 200
def post(self, course_code, student_id): return { "message": "Student enrolled", "course": course_code, "student_id": student_id }, 201
api.add_resource(StudentResource, '/students', '/students/<int:student_id>')api.add_resource(CourseResource, '/courses/<string:course_code>', '/courses/<string:course_code>/enroll/<int:student_id>')
if __name__ == '__main__': app.run(debug=True)Based on the above data, answer the given subquestions.
Consider the following HTTP requests to the same Flask-RESTful application.
What will be the response status code for each request?
Request 1: curl http://127.0.0.1:5000/students -X POST -d "name=Ashish"
Request 2: curl http://127.0.0.1:5000/courses/CS101/enroll/456 -X POST
Request 3: curl http://127.0.0.1:5000/students/789 -X DELETE
Request 1: 400, Request 2: 201, Request 3: 204
Request 1: 201, Request 2: 201, Request 3: 204
Request 1: 400, Request 2: 405, Request 3: 204
Request 1: 201, Request 2: 405, Request 3: 200
Correct answer
Request 1: 400, Request 2: 201, Request 3: 204
Consider the following flask code and answer the given subquestions.
from flask import Flask, request
app = Flask(__name__)
@app.route('/score')def score(): name = request.args.get('name', 'Guest') try: marks = int(request.args.get('marks', 0)) except ValueError: return f"Invalid marks for {name}"
if marks >= 90: grade = "A" elif marks >= 75: grade = "B" elif marks >= 60: grade = "C" else: grade = "F"
return f"{name} scored {marks} and received grade {grade}"
app.run(debug=True)Alex scored 0 and received grade F.
Alex scored eighty and received grade F
Error 500: Internal Server Error
Invalid marks for Alex
Correct answer
Invalid marks for Alex
Consider the following flask code and answer the given subquestions.
from flask import Flask, request
app = Flask(__name__)
@app.route('/score')def score(): name = request.args.get('name', 'Guest') try: marks = int(request.args.get('marks', 0)) except ValueError: return f"Invalid marks for {name}"
if marks >= 90: grade = "A" elif marks >= 75: grade = "B" elif marks >= 60: grade = "C" else: grade = "F"
return f"{name} scored {marks} and received grade {grade}"
app.run(debug=True)Guest scored 88 and received grade A
Guest scored 0 and received grade F
Guest scored 88 and received grade B
Invalid marks for Guest
Correct answer
Guest scored 88 and received grade B
Consider the following flask code and answer the given subquestions.
from flask import Flask, request
app = Flask(__name__)
@app.route('/score')def score(): name = request.args.get('name', 'Guest') try: marks = int(request.args.get('marks', 0)) except ValueError: return f"Invalid marks for {name}"
if marks >= 90: grade = "A" elif marks >= 75: grade = "B" elif marks >= 60: grade = "C" else: grade = "F"
return f"{name} scored {marks} and received grade {grade}"
app.run(debug=True)Anya scored 59.5 and received grade F
Invalid marks for Anya
Anya scored 0 and received grade F
Anya scored 59 and received grade F
Correct answer
Invalid marks for Anya