Quiz Space

January 2024 term · Modern Application Development I · BSCS2003

MAD 1 End Term: 28 April 2024, Set QDF1 (January 2024 term)

The IIT Madras BS Modern Application Development I (MAD 1) End Term paper sat on 28 Apr 2024, in the January 2024 term, set QDF1: 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
26
MSQ
6

Updated

Official paper: IIT M FOUNDATION DIPLOMA AN EXAM QDF3 28 Apr 2024 · No negative marking.

Question 1

+3 marksOne correct option

Consider the following Python code snippet.

python
from string import Template as makeTemplate
from jinja2 import Template
import sys
var = sys.argv[0]
data = {"var1": "Data scientist", "var2": "programming",
"var3": "statistical", "var4": "insights"}
temp = "{{var1}} creates $var2 code with $var3 knowledge to create
{{var4}}."
if var == "1":
temp = makeTemplate(temp)
output = temp.substitute(data)
print(output)
else:
temp = Template(temp)
output = temp.render(data)
print(output)

What will be printed on the terminal for the command python app.py 1 2 ?

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

Correct answer

  • B

Question 2

+2 marksOne correct option

Consider the following flask application running locally on http://127.0.0.1:5000 ?

python
from flask import Flask
app = Flask(__name__)
@app.route('/home/<string:url>')
def get_url_str(url):
return "string "+url
@app.route('/home/<path:url>')
def get_url_pth(url):
return "path "+url
app.run(debug = True)

Which of the following URLs will throw a 404 Not Found error?

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

Correct answer

  • D

Question 3

+2 marksOne correct option

Consider the following view function.

python
from flask import Flask, request
app = Flask(__name__)
@app.route('/student', methods = ['GET', 'POST'])
def show_details():
cred = request.args
details = {
'Stream': cred['dept'],
'Roll': cred['roll'],
'Course': cred['course']
}
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 4

+2 marksOne correct option

Which of the following is true about the term “stateless” in the client-server model?

  1. A

    The server responds to the client based on the previous state.

  2. B

    The server uses FTP protocol to respond to the client's request.

  3. C

    Server use the URL to convey information to the client.

  4. D

    Server is not required to maintain any state of client or session during transactions between client and server.

Show answer

Correct answer

  • D

    Server is not required to maintain any state of client or session during transactions between client and server.

Question 5

+2 marksOne correct option
  1. A

    GET

  2. B

    POST

  3. C

    PUT

  4. D

    DELETE

Show answer

Correct answer

  • B

    POST

Question 6

+2 marksOne correct option

Which of the below JavaScript statement(s) are used to print information on the browser’s console?

  1. A

    window.alert()

  2. B

    console.log()

  3. C

    document.write()

  4. D

    None of these

Show answer

Correct answer

  • B

    console.log()

Question 7

+2 marksOne correct option

Which command of the below command creates a new branch in GIT?

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

Correct answer

  • B

Question 8

+2 marksOne correct option

Consider the following statements and select the correct option:
Statement 1: In a database, an index can only be created on one column of a table.
Statement 2: Indexes cannot be created on columns which have duplicate values.

  1. A

    Statement 1 is true & statement 2 is false

  2. B

    Statement 2 is true & statement 1 is false

  3. C

    Both statements 1 and 2 are true

  4. D

    Both statements 1 and 2 are false

Show answer

Correct answer

  • D

    Both statements 1 and 2 are false

Question 9

+3 marksOne correct option

In the code snippet given below, what should come in place of code 1 and code 2 such that one book can have multiple sections and the converse does not hold true?

python
from sqlalchemy import ForeignKey
from sqlalchemy import Integer, Column
from sqlalchemy.orm import DeclarativeBase
from sqlalchemy.orm import relationship
class Base(DeclarativeBase):
Pass
class Section(Base):
__tablename__ = "section_table"
id = Column(Integer, primary_key=True)
# write your code 1 here
class Book(Base):
__tablename__ = "book_table"
id = Column(Integer, primary_key=True)
# write your code 2 here
  1. A
  2. B
  3. C
  4. D
Show answer

Correct answer

  • D

Question 10

+3 marksOne correct option

Consider the following flask app and Jinja2 template.

app.py

python
from flask import Flask, render_template
app = Flask(__name__)
@app.route('/')
def index():
return render_template("index.html", data=['Harry', 'Karl', 'John',
'Jason', 'Ros'])
app.run()

index.html

html
<!DOCTYPE html>
<html lang="en">
<head>
<title>Macro</title>
</head>
<body>
{% macro unordered_list(items)%}
<ul>
{% for item in items %}
{% if item|length <= 4 %}
<li>{{item}}</li>
{% endif %}
{% endfor %}
</ul>
{% endmacro %}
{{ unordered_list(data) }}
</body>
</html>

If the flask app is running locally on http://127.0.0.1:5000. What will be the output on the browser for the base URL?

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

Correct answer

  • D

Question 11

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

Correct answer

  • C

Question 12

+3 marksOne correct option

Consider the following flask application.

python
from flask import Flask, render_template, request
app = Flask(__name__)
@app.route('/')
def square():
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 = (int(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 URL http://localhost:5000/?num=2 ?

  1. A

    4

  2. B

    22

  3. C

    ValueError

  4. D

    2

Show answer

Correct answer

  • B

    22

Question 13

+3 marksOne correct option

Consider the following Python code snippet.

log.py

python
import logging
import sys
logging.basicConfig(level=logging.WARNING,
format='%(asctime)s - %(levelname)s - %(message)s')
def check_val(value):
if value < 0:
raise ValueError("Invalid value: Please enter a positive value.")
else:
logging.info("Value added: %s", value)
try:
input_value = int(sys.argv[1])
check_val(input_value)
except ValueError as ve:
logging.exception("Exception occurred: %s", str(ve))

What will be the output on the terminal for the command: python log.py -34 ?

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

Correct answer

  • C

Question 14

+3 marksOne correct option

You have a DRAM module with bus width of 64 bits, clock speed of 2 GHz, and operating in DDR (double-data-rate or two values per clock cycle) mode. What is the maximum bandwidth (in Giga- bytes per second) of data transfer achievable with this module?

  1. A

    16

  2. B

    8

  3. C

    32

  4. D

    128

Show answer

Correct answer

  • C

    32

Question 15

+3 marksOne correct option

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 {
"Course_1": arg1["val"],
"Course_2": arg2["val"],
"Course_3": val
}
api.add_resource(RestApi, "/api/courses/<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:

bash
curl http://127.0.0.1:5000/api/courses/DBMS?val=JAVA -d
"{\"val\":\"PDSA\"}" -X POST -H "Content-Type: application/json"
  1. A
  2. B
  3. C
  4. D
Show answer

Correct answer

  • C

Question 16

+3 marksOne correct option
  1. A

    The special series is: 1 0 1 0 1 0 1 0 1 0 1 0 1 0

  2. B

    The special series is: 1 2 0 1 2 0 1 2 0 1 2 0 1 2

  3. C

    The special series is: 1.0 0.0 1.0 0.0 1.0 0.0 1.0 0.0 1.0 0.0 1.0 0.0 1.0 0.0

  4. D

    The special series is: 0.33 0.67 1.0 1.33 1.67 2.0 2.33 2.67 3.0 3.33 3.67 4.0 4.33 4.67

Show answer

Correct answer

  • D

    The special series is: 0.33 0.67 1.0 1.33 1.67 2.0 2.33 2.67 3.0 3.33 3.67 4.0 4.33 4.67

Question 17

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

Correct answer

  • C

Question 18

+3 marksOne correct option

Consider the below two data models Author and Book using SQLite database.

python
class Author(db.Model):
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String)
dob = db.Column(db.String)
class Book(db.Model):
id = db.Column(db.Integer(), primary_key=True)
title = db.Column(db.String())
publisher = db.Column(db.String())
written_by = db.Column(db.Integer(), db.foreign_key("author.id"))

What kind of relationship exists between Author and Book classes?

  1. A

    One Book to one Author relationship

  2. B

    One Author to many Books relationship

  3. C

    Many Authors to one Book relationship

  4. D

    Many Books to many Author relationship

Show answer

Correct answer

  • B

    One Author to many Books relationship

Question 19

+4.5 marksOne correct option

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**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) == 13
def test_case3(self):
assert func(6,2) == 38
class Test_class1():
def test_case1(self):
assert func(5,2) == 29
def case_test2(self):
assert func(1,1) == 2

What will be the output on the terminal for the command below?

bash
pytest test_file.py -k Test_class
  1. A
  2. B
  3. C
  4. D
Show answer

Correct answer

  • D

Question 20

+4.5 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 %}
<p>MAD I</p>
<span>MAD II</span>
<span>DBMS</span>
{% endblock %}

base.html

html
<!DOCTYPE html>
<html lang="en">
<head>
<title>IITM</title>
</head>
<body>
<h2 style="color: violet;"> Diploma Courses </h2>
{% 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

  • C

Question 21

+4.5 marksOne correct option

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. What is the total data consumed in GigaBytes by all the users in 24 hrs?

  1. A

    547.2 GB

  2. B

    12 GB

  3. C

    43.2 GB

  4. D

    345.6 GB

Show answer

Correct answer

  • C

    43.2 GB

Question 22

+4.5 marksOne correct option

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": "Ramesh", "Roll_No":"user123",
"Email":"ramesh.user@kmail.com"}
class Student(Resource):
def delete(self):
data = request.json
student_info.update(data)
return student_info
def put(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:

bash
curl -X PUT -H "Content-Type: application/json" -H "Accept-Type:
application/json" -d "{\"Roll_No\":\"user321\", \"Email\":
\"r.user@kmail.com\"}" http://127.0.0.1:5000/

2:

bash
curl -X DELETE -H "Content-Type: application/json" -H "Accept-Type:
application/json" -d "{\"Roll_No\":\"user321\", \"Email\":
\"r.user@kmail.com\"}" http://127.0.0.1:5000/
  1. A
  2. B
  3. C
  4. D
Show answer

Correct answer

  • A

Question 23

+4.5 marksOne correct option

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;}
#two{color: green}
#three{color: green;}

HTML Code:

html
<!DOCTYPE html>
<html>
<head>
<title>Document</title>
<link href="style.css" rel="stylesheet">
<style>
body{font-weight: bold;}
p{color: violet !important ;}
</style>
</head>
<body>
<span id="one">Content 1</span>
<span class="two" id="two" >Content 2</span>
<p id="three">Content 3</p>
</body>
</html>
  1. A
  2. B
  3. C
  4. D
Show answer

Correct answer

  • C

Question 24

+4.5 marksOne correct option

Consider the below two python files code snippets app.py and test_app_route.py.

app.py

python
from flask import Flask
app = Flask(__name__)
@app.route("/greet/<string:name>")
def home(name):
return "Hello, " + name
if __name__ == "__main__":
app.run()

test_app_route.py:

python
import pytest, requests
@pytest.fixture
def get_response():
resp = requests.get("http://127.0.0.1:5000/greet/IITM")
return resp
def test_response(get_response):
assert get_response.text == "Hello, IITM"

Assume that app.py and test_app_route.py are running on two different terminals and all required modules are installed, then which of the following is the correct option for the statements given below?

i) Executing the command pytest test_app_route.py on the terminal returns
=========== 1 passed =============

ii) Executing the command pytest test_app_route.py on the terminal returns
============ 1 failed ==============

iii) Executing the command pytest test_app_route.py on the terminal returns
============ 1 selected, 1 passed ==============

iv) Executing the command pytest test_app_route.py on the terminal returns
============ 1 deselected ==============

  1. A

    Statements i and iii are correct

  2. B

    Statements ii and iv are correct

  3. C

    Only statement i is correct

  4. D

    Only statement ii is correct

Show answer

Correct answer

  • C

    Only statement i is correct

Question 25

+2 marksOne or more correct options

Select all that apply.

  1. A

    An employee can exist without having any salary slips

  2. B

    An employee can have more than one salary slip

  3. C

    An employee needs to have at least one salary slip

  4. D

    A salary slip must belong to one and only one employee

Show answer

Correct answers

  • A

    An employee can exist without having any salary slips

  • B

    An employee can have more than one salary slip

  • D

    A salary slip must belong to one and only one employee

Question 26

+3 marksOne or more correct options

Consider the following python code snippet.

python
from string import Template
statement = "The $animal jumped over the $obstacle."
temp = Template(statement)
print(=== OUTPUT ===)

Which of the following statements, when substituted in place of === OUTPUT ===, will not throw a KeyError?

Select all that apply.

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

Correct answers

  • B
  • C
  • D

Question 27

+3 marksOne or more correct options

Which of the below is/are true about the Web Server?

Select all that apply.

  1. A

    Always web server response in HTML format

  2. B

    Web servers process the business logic and return different types of responses

  3. C

    Web servers can host multiple web applications

  4. D

    The web server sends the requested web page using HTTP

Show answer

Correct answers

  • B

    Web servers process the business logic and return different types of responses

  • C

    Web servers can host multiple web applications

  • D

    The web server sends the requested web page using HTTP

Question 28

+3 marksOne or more correct options

Consider a client ‘C’ and a server ‘S’, separated by distance ‘D’ are connected by a fictitious medium in which the speed of light is ‘v’ m/sec. If ‘N’ is the number of consecutive requests that can made in a second by the client ‘C’ (i.e A new request can be made only after receiving the response from the previous request.), Which of the following changes would halve the number ‘N’?

Select all that apply.

  1. A

    A change of medium where the speed of light is 2v m/sec.

  2. B

    Reduce the distance between C and S from D to D/2.

  3. C

    A change of medium where the speed of light is v/2 m/sec.

  4. D

    Increase the distance between C and S from D to 2D.

Show answer

Correct answers

  • C

    A change of medium where the speed of light is v/2 m/sec.

  • D

    Increase the distance between C and S from D to 2D.

Question 29

+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('/library')
def home():
return 'Select your course!'
@app.route('/student/<username>/<roll>')
def dashboard(username):
return f'{username}\'s dashboard'
with app.test_request_context():
#== print statement ==#

Select all that apply.

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

Correct answers

  • B
  • C

Question 30

+4.5 marksOne or more correct options

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

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(10) == 100
@pytest.mark.marker2
def testcase_2():
assert square(4) == 4
@pytest.mark.marker3
def testcase_3():
assert square(5) == 25
@pytest.mark.marker4
def testcase_4():
assert square(6) == 6

On running this file on the terminal using pytest, the summary of the output is;

text
========= 1 failed, 3 deselected, 4 warnings in 0.17s =========

What command will result into the outcome given above?

Select all that apply.

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

Correct answers

  • B
  • D

Question 31

+3 marksOne correct option

Consider the following Python code snippet.

file.py

python
import sys
courses = {
1: "App Dev I",
2: "App Dev II",
3: "App Dev III",
4: "DevOps"
}
if courses[int(sys.argv[2])] in "App Dev III":
i = 1
while i <= int(sys.argv[2]):
print("course found",courses[i])
i+=1
else:
print("No course found!")

Based on the above data, answer the given subquestions.

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

Correct answer

  • D

Question 32

+3 marksOne correct option

Consider the following Python code snippet.

file.py

python
import sys
courses = {
1: "App Dev I",
2: "App Dev II",
3: "App Dev III",
4: "DevOps"
}
if courses[int(sys.argv[2])] in "App Dev III":
i = 1
while i <= int(sys.argv[2]):
print("course found",courses[i])
i+=1
else:
print("No course found!")

Based on the above data, answer the given subquestions.

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

Correct answer

  • C