Home / Past papers / MAD1 End Term / this paper
Consider the following snippet of HTML and its output rendered on the browser: index.html
```html
<form action="/">
<label for="fname">What is your first name?</label><br>
<input type="text" name="fname" id="fname"><br>
<input type="submit" value="Submit">
</form>
```
A web browser window is displayed.
The title bar shows "Form" on the left and "Private browsing" in the center.
The address bar shows "localhost:5000".
The main content area displays:
"What is your firstname?"
Below this is an empty text input field.
Below the text input field is a button labeled "Submit".
Which HTTP request would be sent to the server if the user enters "Mahesh" into the text box and clicks submit?
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 {
"value_1": arg1["val"],
"value_2": arg2["val"],
"value_3": val
}
api.add_resource(RestApi, "/api/games/<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:
`curl http://127.0.0.1:5000/api/games/cricket?val=soccer -d "{\"val\":\"tennis\"}" -X POST -H "Content-Type: application/json"`
```json
{
"value_1": "soccer",
"value_2": "tennis",
"value_3": "cricket"
}
```
```json
{
"value_1": "cricket",
"value_2": "soccer",
"value_3": "tennis"
}
```
```json
{
"value_1": "tennis",
"value_2": "soccer",
"value_3": "cricket"
}
```
```json
{
"value_1": "tennis",
"value_2": "cricket",
"value_3": "soccer"
}
```
Consider the following function to be tested and test functions given in the Python code snippet below. On running this file on the terminal using pytest, the summary of the output is;
Consider the following function to be tested and test functions given in the Python code snippet below. On running this file on the terminal using pytest, the summary of the output is; What command will result into the outcome given above?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(11) == 121
@pytest.mark.marker2
def testcase_2():
assert square(8) == 8
@pytest.mark.marker3
def testcase_3():
assert square(5) == 36
```
```
======== 1 passed, 2 deselected, 3 warnings in 0.02s ========
```
``` pytest test_file.py -k marker1 ```

``` pytest test_file.py -m marker1 ```

``` pytest test_file.py -m marker2 ```

``` pytest test_file.py -m marker3 ```

The hexadecimal equivalent of the IPv4 address 192.168.72.101 would be _________
An HTML code and CSS code is given below. Which of the following correctly represents its rendered output?
An HTML code and CSS code is given below. Which of the following correctly represents its rendered output? CSS Code:
```css
.one{color: blue;}
.two{color: red !important;}
.three{color: green;}
```
HTML Code:
```html
<!DOCTYPE html>
<html>
<head>
<title>Document</title>
<link href="style.css" rel="stylesheet">
<style>
body{background-color: aqua; text-align: center;}
h2{color: violet !important ;}
</style>
</head>
<body style="background-color:lavender;" >
<h2 style="color: blue;">Welcome to IIT</h2>
<p class="one">My content 1 </p>
<p class="two" style="color: brown;">My content 2</p>
<p class="three">My content 3</p>
</body>
</html>
```
Welcome to IIT My content 1 My content 2 My content 3

Welcome to IIT My content 1 My content 2 My content 3

Welcome to IIT My content 1 My content 2 My content 3

Welcome to IIT My content 1 My content 2 My content 3

Consider the following models Student and Project corresponding to tables student and project in SQLite database.
```python
class Student(db.Model):
id = db.Column(db.Integer(), primary_key = True)
name = db.Column(db.String(), unique = True)
class Project(db.Model):
id = db.Column(db.Integer(), primary_key = True)
title = db.Column(db.String(), unique = True)
course = db.Column(db.Integer(), db.ForeignKey("course.id"))
```
Based on the model schemas, what relationship do the classes Student and Project share?
Consider the following Python code snippet. ```python
from flask import Flask
from flask_restful import Api, Resource
app = Flask(__name__)
api = Api(app)
class MyApi(Resource):
def get(self, get):
return {"greet":"Hello from GET Api!"}
def put(self):
return {"greet":"Hello from PUT Api!"}
api.add_resource(MyApi, '/api/<get>', '/api/put')
app.run()
```
If this application is running locally on http://127.0.0.1:5000, which of the following curl commands will throw an error?
1. `curl http://127.0.0.1:5000/api/get -X get`
2. `curl http://127.0.0.1:5000/api/put -X put`
3. `curl http://127.0.0.1:5000/api/post -X get`
4. `curl http://127.0.0.1:5000/api/get -X put`
Consider the code below and match the conditions in Column A with respect to the coverage types in Column B. ```c
int foo(int x, int y)
{
int z = 0;
if((x > 0) && (y > 0))
{
z = x;
}
return z;
}
```
| Column A | Column B |
|---|---|
| 1. Test invokes foo() at least once | a. Condition coverage |
| 2. foo(1,1) | b. Branch coverage |
| 3. foo(1,1) and foo(1,0) | c. Function coverage |
| 4. foo(0,1) and foo(1,0) | d. Statement coverage |
Match the following types of testing with their functionality. Which of the following is the correct matching?| A. Regression testing | 1. Beta Testing | |---|---| | B. User Acceptance testing | 2. One step beyond integration Testing | | C. System testing | 3. Simulates actual user interaction, allows to script browser | | D. System testing Automation | 4. Type of testing that runs after every change to ensure that the change introduces no unintended breaks. |
Consider the following table “emp” created in SQLite database corresponding to model class “Employee” using flask_sqlalchemy. Which of the following code snippets will change the designation of male teachers to professor and will increase their salaries to 6000 correctly when typed in the Python console?| Id | Name | Designation | Gender | Salary | |---|---|---|---|---| | 1 | Raji | Headmaster | Female | 4500 | | 2 | Ram | Teacher | Male | 5000 | | 3 | Raveena | Teacher | Female | 3000 | | 4 | Reshma | Technical staff | Female | 2000 | | 5 | Ravi | Teacher | Male | 1000 |

```python >>> emp = Employee.query.filter_by(Designation = 'Teacher').all() >>> for staff in emp: ... staff.Designation="Professor" ... staff.Salary = 6000 ... >>> db.session.commit() ```

```python >>>emp = Employee.query.filter_by(Designation="Teacher",Gender="Male").all() >>> for staff in emp: ... staff.Designation="Professor" ... staff.Salary +=6000 ... >>> db.session.commit() ```

```python >>> emp = Employee.query.filter_by(Designation = 'Teacher').all() >>> for staff in emp: ... staff.Designation="Professor" ... staff.Salary += 6000 ... >>> db.session.commit() ```

```python >>> emp=Employee.query.filter_by(Designation="Teacher", Gender="Male").all() >>> for staff in emp: ... staff.Designation="Professor" ... staff.Salary=6000 ... >>> db.session.commit() ```
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>Welcome to MAD I</h3>
{% endblock %}
```
base.html
```html
<!DOCTYPE html>
<html lang="en">
<head>
<title>IITM</title>
</head>
<body>
<h1 style="color: violet;"> IITM BS Degree </h1>
{% block content %}
{% endblock %}
</body>
</html>
```
What will be the rendered output for base URL if flask app is running locally on
http://localhost:5000
Welcome to MAD I

Welcome to MAD I IITM BS Degree

IITM BS Degree Welcome to MAD I

Error
Consider the following SQL create statement. ```sql
CREATE TABLE car (
car_id INTEGER NOT NULL,
model INTEGER NOT NULL,
name VARCHAR(50),
mfd_date DATETIME NOT NULL,
description VARCHAR,
PRIMARY KEY (car_id),
UNIQUE (model),
UNIQUE (name)
)
```
Which of the following flask_sqlalchemy models will create exactly the same table as created by the above SQL command?
```python
class Car(db.Model):
car_id = db.Column(db.Integer(), unique = True, nullable = False)
model = db.Column(db.Integer(), autoincrement = True)
name = db.Column(db.String(50), unique = True, nullable = True)
mfd_date = db.Column(db.DateTime(), nullable = False)
description = db.Column(db.String())
```
```python
class Car(db.Model):
car_id = db.Column(db.Integer(), primary_key = True)
model = db.Column(db.Integer(), unique = True, nullable = True)
name = db.Column(db.String(50), unique = False)
mfd_date = db.Column(db.DateTime(), nullable = False)
description = db.Column(db.String())
```
```python
class Car(db.Model):
car_id = db.Column(db.Integer(), primary_key = True)
model = db.Column(db.Integer(), unique = True, nullable = False)
name = db.Column(db.String(), unique = True, nullable = True)
mfd_date = db.Column(db.DateTime())
description = db.Column(db.String(50))
```
```python
class Car(db.Model):
car_id = db.Column(db.Integer(), primary_key = True)
model = db.Column(db.Integer(), unique = True, nullable = False)
name = db.Column(db.String(50), unique = True, nullable = True)
mfd_date = db.Column(db.DateTime(), nullable = False)
description = db.Column(db.String())
```
``` git rm <filename> ```

``` git del <filename> ```

``` git del --cached <filename> ```

``` git rm --cached <filename> ```
Consider the following python code snippet. ```python from string import Template statement = "The four major operations on the database are $c, $r, $u and $d." temp = Template(statement) print(=== OUTPUT ===) ``` Which of the following statements, when substituted in place of === OUTPUT ===, will not throw a KeyError?

```python
temp.safe_substitute({"c": "CREATE", "r": "READ", "u": "UPDATE",
"d": "DELETE"})
```
```python
temp.safe_substitute({"c": "CREATE", "r": "READ", "u": "UPDATE"})
```
```python
temp.safe_substitute({"c":"CREATE", "r":"READ", "u":"UPDATE",
"d":"DELETE", "e":"TRUNCATE"})
```
```python
temp.substitute({"c":"CREATE","r":"READ","u":"UPDATE",
"d":"DELETE", "e":"TRUNCATE"})
```
Consider the following TodoSimple resource class created using flask_restful.
```python
from flask import Flask, request
from flask_restful import Resource, Api
app = Flask(__name__)
api = Api(app)
class TodoSimple(Resource):
def get(self, todo_id):
return {"todo_id": todo_id}
def put(self):
todo_id = request.args.get("todo_id")
return {"todo_id": todo_id}
app.run()
```
Which of the following statements given below will correctly map the resource URLs with the TodoSimple resource class.
```python api.add_resource(TodoSimple, "/api") ```

```python api.add_resource(TodoSimple, "/api/<int:todo_id>", "/api") ```

```python api.add_resource(TodoSimple, "/api/<int:todo_id>") ```

```python api.add_resource(TodoSimple, "/<int:todo_id>", "/api") ```

```python
import logging
logging.basicConfig(filename='debug.log', level=logging.DEBUG,
format=f'%(asctime)s %(levelname)s %(name)s %(threadName)s :
%(message)s')
```
```python
import logging
logging.basicConfig(filename='debug.log', level=logging.NOTSET,
format=f'%(asctime)s %(levelname)s %(name)s %(threadName)s :
%(message)s')
```
```python import logging logging(filename='debug.log', level=logging.DEBUG) ```

```python import logging logging.basicConfig(filename='debug.log') ```
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. Which user has consumed the highest amount of data? This is a 2D line graph with a horizontal x-axis labeled "Time (Hours)" and a vertical y-axis labeled "BandWidth Megabits/s". The x-axis ranges from 0 to 24, with major tick marks at 0, 4, 8, 12, 14, 16, 20, and 24. Vertical dashed lines extend from each of these major tick marks upwards. The y-axis ranges from 0 to 12, with major tick marks at 0, 2, 4, 6, 8, 10, and 12. There are three horizontal colored lines at the top of the graph, representing users: - A blue line labeled "user 1" extends from x=0 to x=4, at y=11. - A yellow line labeled "user 2" extends from x=8 to x=14, at y=11. - A green line labeled "user 3" extends from x=16 to x=24, at y=11. An orange step-function line is plotted across the graph: - From x=0 to x=4, the line is at y=8. - From x=4 to x=8, the line is at y=10. - From x=8 to x=12, the line is at y=6. - From x=12 to x=16, the line is at y=8. - From x=16 to x=20, the line is at y=2. - From x=20 to x=24, the line is at y=4.
Consider the following restful implementation using flask. ```python
from flask import Flask, request
from flask_restful import Resource, Api
app = Flask(__name__)
api = Api(app)
student_info = {"name": "Rahul", "Roll No":"12d2000678",
"Email":"onlinedegree.iitm.ac.in"}
class Student(Resource):
def put(self):
data = request.json
student_info.update(data)
return student_info
def delete(self):
student_info.popitem()
return "success", 200
api.add_resource(Student, '/')
app.run()
```
If the above application is running on "http://127.0.0.1:5000" then what will be the final output on
terminal on executing these two curl commands in the order mentioned?
1: `curl -X DELETE 'http://127.0.0.1:5000'`
2: `curl -X PUT -H "Content-Type: application/json" -H "Accept-Type:
application/json" -d '{"Roll No":"12f2000555", "Email":
"ds.study.iitm.ac.in"}' 'http://127.0.0.1:5000/'`
```json
{"name": "Rahul", "Roll No": "12F2000555", "Email": "ds.study.iitm.ac.in"}
```
```json
{"name": "Rahul", "Roll No": "12f2000555"}
```
```json
{"Roll No":"12f2000555", "Email":"ds.study.iitm.ac.in"}
```
None of these
Consider the following python code snippet. What will be the rendered output? ```python
from jinja2 import Template
persons=[
{"Gender":"Male", "Age":40, "Name":"John"},
{"Gender":"Female", "Age":16, "Name":"Samantha"},
{"Gender":"Male", "Age":20, "Name":"Kim"}
]
t="""
<ul>
{% for group in persons|groupby('Gender') %}
<li>
{{ group.grouper }}
<ul>
{% for person in group.list %}
<li>{{ person.Name }} is {{ person.Age }} years old</li>
{% endfor %}
</ul>
</li>
{% endfor %}
</ul>
"""
temp=Template(t)
print(temp.render(persons=persons))
```
- Male - John is 40 years old - Female - Samantha is 16 years old - Male - Kim is 20 years old

- Male - John is 40 years old - Kim is 20 years old - Female - Samantha is 16 years old

- Female - Samantha is 16 years old - Male - John is 40 years old - Kim is 20 years old

- Female - Samantha is 16 years old - Male - John is 40 years old - Male - Kim is 20 years old

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+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(6,2) == 8
class Test_class1():
def test_case1(self):
assert func(5,2) == 9
def case_test2(self):
assert func(4,3) == 14
```
What will be the output on the terminal for the command below?
pytest test_file.py -k Test_class0
```text == 2 failed, 1 passed in 0.17s === ```

```text == 2 failed, 1 deselected in 0.17s ==== ```

```text == 1 failed, 1 passed, 1 deselected in 0.17s ==== ```

``` == 1 failed, 2 passed in 0.17s === ```
What will be the output of the following Python code snippet? ```python
def decor(func):
def wrapper(x):
y=func(x)
return x*y
return wrapper
@decor
def output(x, optional="hello world!"):
return x, optional
print(output(5))
```
```
('hello world!', 'hello world!', 'hello world!', 'hello world!',
'hello world!')
```
(5, 5, 5, 5, 5)

``` (5, 'hello world!', 5, 'hello world!', 5, 'hello world!', 5, 'hello world!', 5, 'hello world!') ```

25
Consider the following flask application. ```python
from flask import Flask
app = Flask(__name__)
@app.route('/user/<username>')
def show_user(username):
return f'Hello {username} !'
@app.route("/hello/user")
def hello():
return "Hello, user!"
@app.route("/user/")
def index():
return "Hello user"
if __name__ == "__main__":
app.run(debug=True)
```
If the application is running locally on http://127.0.0.1:5000 then map the URLs in Column A with their rendered outputs in Column B.
| | Column A | | Column B |
|---|---|---|---|
| a | http://localhost:5000/hello/user | 1 | User hello ! |
| b | http://localhost:5000/user/hello | 2 | Hello user ! |
| c | http://localhost:5000/user/user | 3 | Hello hello ! |
| d | http://localhost:5000/user// | 4 | Hello user |
| | | 5 | Hello, user! |
| | | 6 | Not Found |
Consider the following flask application. ```python
from flask import Flask, render_template, request
app = Flask(__name__)
@app.route('/')
def out():
val = request.args
if val['num'] == '':
return "<h1>Enter a valid number</h1>"
elif val['num'].isalpha()==True:
return "<h1>Invalid number</h1>"
else:
out = (val['num']) + (val['num'])
return f'<h1>{out}</h1>'
if(__name__ == "__main__"):
app.run(debug=True)
```
If this flask app is running locally on http://localhost:5000, what is the output for the following URL?
For input: http://localhost:5000/?num=343
Follow the code given below ```python
from flask import Flask, request
from flask_restful import Resource, Api, fields, marshal, marshal_with
app = Flask(__name__)
api = Api(app)
class User:
def __init__(self, id, username, email):
self.id=id
self.username=username
self.email=email
output={"id": fields.Integer,"username": fields.String,"email": fields.String}
## Resource Class Here ==
api.add_resource(Userapi, '/')
if __name__ == '__main__':
app.run()
```
What code should be written in place of `## Resource Class Here ==`, so that we get;
```json
{
"id": 1,
"username": "iitm",
"email": "bs@ds.study.iitm.ac.in"
}
```
as output on running the command `curl -X GET 'http://127.0.0.1:5000'` in the terminal?
```python
class Userapi(Resource):
@marshal_with(output)
def get(self):
user=User(1, "iitm", "bs@ds.study.iitm.ac.in")
return user
```
```python
class Userapi(Resource):
def get(self):
user=User(1, "iitm", "bs@ds.study.iitm.ac.in")
return user
```
```python
@marshal_with(output)
class Userapi(Resource):
def get(self):
user=User(1,"iitm", "bs@ds.study.iitm.ac.in")
return user
```
```python
class Userapi(Resource):
def get(self):
user=User(1, "iitm", "bs@ds.study.iitm.ac.in")
return marshal(user, output)
```Auto-generated summary from the source site. Handy as a checklist; the lessons above explain each idea from scratch.
Here’s a structured summary of the core topics, concepts, principles, and equations for the "Modern Application Development 1" exam, along with Mermaid knowledge graphs to visualize relationships.
HTTP Methods:
GET: Fetches data (data in URL query params).POST: Submits data (data in request body).PUT: Updates/replaces data.DELETE: Deletes data.Example (Q2):
POST / HTTP/1.1
Content-Type: application/x-www-form-urlencoded
fname=Mahesh # Form data in bodyHTML Forms:
GET (appends data to URL).action: URL to submit data.method: HTTP method (GET/POST).Client-Side vs. Server-Side Validation:
required, JavaScript).Flask Basics:
@app.route('/path').request.args (query params), request.json (body).Example (Q4):
@app.route('/api/games/<val>')
def post(self, val):
arg1 = parser.parse_args() # Body data (JSON)
arg2 = request.args # Query paramsFlask-RESTful:
Example (Q9):
class MyApi(Resource):
def get(self): return {"greet": "Hello"}
api.add_resource(MyApi, '/api/<val>')HTTP Status Codes:
200 OK, 404 Not Found, 500 Server Error.SQLAlchemy Models:
Example (Q14):
class Car(db.Model):
car_id = db.Column(db.Integer, primary_key=True)
model = db.Column(db.Integer, unique=True)Relationships:
ForeignKey exists.CRUD Operations:
db.session.add(), db.session.commit().Example (Q12):
emp = Employee.query.filter_by(Gender="Male").all()
for staff in emp:
staff.Salary = 6000
db.session.commit()Pytest:
@pytest.mark.marker1.pytest -m marker1.Example (Q5):
pytest test_file.py -m marker2 # Runs only marker2 testsTest Coverage Types (Q10):
if/else) tested.Debugging:
logging.basicConfig(filename='debug.log', level=logging.DEBUG).Git Commands:
git rm --cached <file>: Remove from staging (keep locally).git add, git commit, git push.Branching:
git branch, git checkout.Disk Latency (Q3):
IPv4 to Hex (Q6):
192 → C0).192.168.72.101 → C0.A8.48.65.Bandwidth vs. Data Consumption (Q25):
CSS Specificity:
!important > Inline > ID > Class > Element.Example (Q7):
.two { color: red !important; } /* Highest priority */Jinja2 Templating (Q27):
{% for %}, {{ variable }}, |groupby.Example Output:
<ul>
<li>Male
<ul>
<li>John is 40</li>
<li>Kim is 20</li>
</ul>
</li>
</ul>IaaS vs. PaaS vs. SaaS:
Selection Sort-like Algorithm:
Steps:
| Topic | Key Points |
|---|---|
| Cold Storage (Q24) | Low cost, high durability, high retrieval latency (e.g., AWS Glacier). |
| Alexa View (Q23) | AI Voice and LED Light (user-facing components). |
| Logging (Q22) | logging.basicConfig(filename='debug.log', level=logging.DEBUG). |
| Decorators (Q29) | Modify function behavior (e.g., @decor wraps output). |
Time Complexity (Q31):
request.args vs. request.json, route definitions.-m), coverage types.rm --cached vs. rm.!important > inline > ID > class).