Question 1
Consider the following snippet of HTML and its output rendered on the browser:
GET
POST
PUT
DELETE
The IIT Madras BS Modern Application Development I (MAD 1) End Term paper sat on 3 Sept 2023, in the May 2023 term, set QPD1-S2: 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.
Consider the following snippet of HTML and its output rendered on the browser:
GET
POST
PUT
DELETE
Correct answer
GET
A 6000 rpm magnetic disk is being used to store data. The disk can only spin in one direction and is operating at 6000 revolutions per minute. If the operating system sends a request to the disk controller to fetch data from the disk, but by the time the request reached the disk controller, the information had already moved 35 degrees passed the reader, what will be the latency (in milliseconds) before it can start retrieving data?
0.97
9.03
90.3
97
Correct answer
9.03
Consider the following flask resource created using flask_restful.
from flask import Flask, requestfrom 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"Correct answer
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(11) == 121
@pytest.mark.marker2def testcase_2(): assert square(8) == 8
@pytest.mark.marker3def testcase_3(): assert square(5) == 36On running this file on the terminal using pytest, the summary of the output is;
What command will result into the outcome given above?
Correct answer
C048 A865
C0A8 4865
C0A8 6548
C065 A848
Correct answer
C0A8 4865
An HTML code and CSS code is given below. Which of the following correctly represents its rendered output?
HTML Code:
<!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>Correct answer
Consider the following models Student and Project corresponding to tables student and project in SQLite database.
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?
Many-to-Many
One-to-Many
One-to-One
The tables are not at all related
Correct answer
The tables are not at all related
Consider the following Python code snippet.
from flask import Flaskfrom 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?
curl http://127.0.0.1:5000/api/get -X getcurl http://127.0.0.1:5000/api/put -X putcurl http://127.0.0.1:5000/api/post -X getcurl http://127.0.0.1:5000/api/get -X putOnly 2 and 4
Only 4
Only 3 and 4
Only 3
Correct answer
Only 4
Consider the code below and match the conditions in Column A with respect to the coverage types in Column B.
1-d, 2-a, 3-b, 4-c
1-c, 2-d, 3-b, 4-a
1-c, 2-d, 3-a, 4-b
1-b, 2-d, 3-c, 4-a
Correct answer
1-c, 2-d, 3-b, 4-a
Match the following types of testing with their functionality.
Which of the following is the correct matching?
A → 1, B → 2, C → 3, D → 4
A → 4, B → 3, C → 2, D → 1
A → 3, B → 2, C → 1, D → 4
A → 4, B → 1, C → 2, D → 3
Correct answer
A → 4, B → 1, C → 2, D → 3
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?
Correct answer
Consider the following python code snippet app.py, the html files, base.html and home.html residing in “templates” folder.
app.py
from flask import Flask, render_templateapp = Flask(__name__)@app.route('/')def home(): return render_template('home.html')app.run(debug=True)home.html
{% extends "base.html" %}{% block content %}<h3>Welcome to MAD I</h3>{% endblock %}base.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
Correct answer
Consider the following SQL create statement.
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?
Correct answer
Consider the following statements and select the correct option.
Statement 1: It is not necessary to implement server-side validation if client-side validation has been implemented.
Statement 2: Client-side validation can be implemented with HTML5.
Statement 1 is true while statement 2 is false
Statement 2 is true while statement 1 is false
Both statements are true
Both statements are false
Correct answer
Statement 2 is true while statement 1 is false
Consider the following statements and select the correct answer.
Statement 1: In PaaS, developers are provided with an up-to-date development environment with the languages and frameworks of their choice.
Statement 2: Microsoft Azure provides IaaS as well as PaaS services.
Statement 1 is true, but statement 2 is false
Statement 2 is true, but statement 1 is false
Both statements are false
Both statements are true
Correct answer
Both statements are true
Consider the following statements and choose the correct option.
Statement 1: If we submit the form using the GET method, then the form data is appended inside the body of the HTTP request.
Statement 2: Never use GET method in form to send sensitive data while it is good for non-secure data, like query strings in Google
Both statements 1 and 2 are true, and statement 2 is a correct explanation of statement 1
Both statements 1 and 2 are true, but statement 2 is not a correct explanation of statement 1
Statement 1 is true and statement 2 is false
Statement 2 is true and statement 1 is false
Correct answer
Statement 2 is true and statement 1 is false
Which of the following git command will remove a file from the staged area but keeps the file in the directory?
Correct answer
Consider the following python code snippet.
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?
Correct answers
Consider the following TodoSimple resource class created using flask_restful.
from flask import Flask, requestfrom 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.
Correct answers
Which of the statements are true?
HTML5 is based on SGML
XHTML is based on XML which in turn is based on SGML
HTML5 is not backwards compatible with older versions of HTML
XML is both human and machine-readable
Correct answers
XHTML is based on XML which in turn is based on SGML
XML is both human and machine-readable
Choose the correct code snippet to implement logging by importing python logging module
Correct answers
Consider a typical Amazon Alexa device. Which of the following would constitute the view of the application behind such a device?
The AI voice
The body of the device
The LED light around the device
None of these
Correct answers
The AI voice
The LED light around the device
Which of the following is true of “cold storage” like Amazon Glacier?
They have low cost and high durability.
They have high cost and low durability.
Latency of retrieval is very low.
Latency of retrieval is very high.
Correct answers
They have low cost and high durability.
Latency of retrieval is very high.
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?
User 1
User 2
User 3
All the three users consumed same amount of data
Correct answer
User 2
Consider the following restful implementation using flask.
from flask import Flask, requestfrom 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/'Correct answer
Consider the following python code snippet. What will be the rendered output?
from jinja2 import Templatepersons=[ {"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))Correct answer
Consider a function func, and a set of test cases given below.
Filename: test_file.py
import pytestdef 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) == 14What will be the output on the terminal for the command below?
pytest test_file.py -k Test_class0Correct answer
What will be the output of the following Python code snippet?
def decor(func): def wrapper(x): y=func(x) return x*y return wrapper
@decordef output(x, optional="hello world!"): return x, optional
print(output(5))Correct answer
Consider the following flask application.
a-2, b-1, c-5, d-6
a-5, b-3, c-2, d-4
a-5, b-1, c-2, d-6
a-2, b-3, c-4, d-6
Correct answer
a-5, b-3, c-2, d-4
Consider the following sorting algorithm which sorts any given unsorted array of numbers in ascending order. What would be its time complexity? (Assume appending and deleting an element from an array does not affect time complexity)
Step 1: Create an empty array.
Step 2: Find the element in the unsorted array with the minimum value.
Step 3: Append this element to the array created in step 1.
Step 4: Delete this element from the unsorted array.
Step 5: Repeat steps 1 to 4 until the unsorted array is empty.
O(N²)
O(N)
O(logN)
O(NlogN)
Correct answer
O(N²)
Consider the following flask application.
from flask import Flask, render_template, requestapp = 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
Correct answer: 343343
Follow the code given below
from flask import Flask, requestfrom 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;
{ "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?
Correct answers