Question 1
Consider that you have installed some python packages using requirements.txt. Which command you will use to list the installed packages in the virtual environment?
pip list
pip freeze
ls -la
ls
The IIT Madras BS Modern Application Development I (MAD 1) End Term paper sat on 1 Sept 2024, in the May 2024 term, set QDF3: 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 that you have installed some python packages using requirements.txt. Which command you will use to list the installed packages in the virtual environment?
pip list
pip freeze
ls -la
ls
Correct answer
pip freeze
A certain text document consisting of only alphanumeric characters (including spaces) takes 1,52,000 bits, when encoded with UCS-4 (32 bit) encoding. How many bits will the same document take if encoded with ASCII 7-bit encoding?
24000 bits
68000 bits
33250 bits
152000 bits
Correct answer
33250 bits
The ability of an application to work with different input modalities beyond keyboard highlights which of the following accessibility principle?
Perceivable
Robust
Understandable
Operable
Correct answer
Operable
Consider the following Python code snippet “code.py”.
Filename: code.py
import sysfrom jinja2 import Templatevars = sys.argv
course_technologies = {'python': 'backend', 'javascript': 'frontend'}template = Template("This course focuses on {{ technology }} development.")
if len(vars) > 2 and vars[2] in course_technologies: course = vars[1] technology = course_technologies[course] print(template.render(technology=technology))else: print("Please specify a valid course name!")Which of the following will be the correct command line input to the terminal to get the output : Please specify a valid course name!. ?
Correct answer
Consider the following flask app and Jinja2 template.
app.py
from flask import Flask, render_templateapp = Flask(__name__)
@app.route('/')def index(): return render_template("index.html", data=['Harry', 'Karl', 'John','Jason', 'Ros'])
app.run()index.html
<!DOCTYPE html><html lang="en"><head> <title>Macro</title></head><body> {% macro unordered_list(items)%} <ul> {% for item in items %} {% if item|length >= 5 %} <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?
Correct answer
A → 1, B → 2, C → 3, D → 4
A → 4, B → 1, C → 2, D → 3
A → 4, B → 3, C → 2, D → 1
A → 3, B → 2, C → 1, D → 4
Correct answer
A → 4, B → 1, C → 2, D → 3
AC0A FE01
CA10 EF0A
AC10 FE0A
AC01 0AEF
Correct answer
AC10 FE0A
Consider the following HTML document with an embedded style sheet.
<!DOCTYPE html><html> <head> <title>Quiz 1</title> <style type="text/css"> div{ padding-left: 10px; margin-right: 15px; border-style: solid; border-width: 5px; width: 2000px; height: 20px; } </style> </head> <body> <div>My first Div element</div> </body></html>Which of the following figures correctly represents the box model of the above HTML document?
Correct answer
1 - c, 2 - a, 3 - b, 4 - d
1 - a, 2 - b, 3 - c, 4 - d
1 - b, 2 - d, 3 - a, 4 - c
1 - d, 2 - c, 3 - b, 4 - a
Correct answer
1 - c, 2 - a, 3 - b, 4 - d
a = 8; b = 10; c = 16;
a = 10; b = 2; c = 16;
a = 8; b = 16; c = 10;
a = 2; b = 16; c = 8;
Correct answer
a = 8; b = 10; c = 16;
a - 4, b - 1, c - 6
a - 5, b - 3, c - 2
a - 5, b - 1, c - 2
a - 5, b - 3, c - 6
Correct answer
a - 5, b - 3, c - 2
Consider the following HTML document.
<!DOCTYPE html><html><head> <style> span { background-color: yellow; color: red; } #id { border: 2px solid purple; color:blue ; display: inline-block; } .class { background-color: aqua; color: red; width:20%; } </style></head><body> <span class="class" id="id">SPAN</span> <span class="class" >SPAN</span> <span>SPAN</span></body></html>How will the browser render above HTML file?
Correct answer
1-c, 2-e, 3-d
1-c, 2-a, 3-b
1-c, 2-a, 3-d
1-a, 2-d, 3-e
Correct answer
1-c, 2-e, 3-d
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 %}<p>MAD I</p><span>MAD II</span><p>DBMS</p>{% endblock %}base.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 ?
Correct answer
Consider the below two python files code snippets app.py and test_app_route.py.
app.py
from flask import Flaskapp = Flask(__name__)
@app.route("/greet/<string:name>")def home(name): return "Hello, " + name
if __name__ == "__main__": app.run()test_app_route.py:
import pytest, requests
@pytest.fixturedef 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 also all required modules are installed. Which of the below statement(s) are True?
i) Executing the command pytest test_app_route.py on the terminal returns<br>=========== 1 passed =============
ii) Executing the command pytest test_app_route.py on the terminal returns<br>============ 1 failed ==============
iii) Executing the command pytest test_app_route.py on the terminal returns<br>============ 1 selected, 1 passed ==============
iv) Executing the command pytest test_app_route.py on the terminal returns<br>============ 1 deselected ==============
Only statement i is correct
Only statement ii is correct
Statements i and iii are correct
Statements ii and iv are correct
Correct answer
Only statement ii is correct
You have a DRAM module with bus width of 8 bits, clock speed of 1.4 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?
2.8
3.2
6.4
12.8
Correct answer
2.8
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 { "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:
curl http://127.0.0.1:5000/api/courses/DBMS?val=JAVA -d"{\"val\":\"PDSA\"}" -X POST -H "Content-Type: application/json"Correct answer
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/logoutCorrect answer
Consider the following flask application.
Python file: app.py
from flask import Flask, render_template, request
app = Flask(__name__)
emp = {'admin':'manoj', 'user':'sumit'}
@app.route('/profile/<user>')def profile(user): access = request.args.get('access') if emp[access] != user: return render_template("profile.html", user = user, access = access, error = True) return render_template("profile.html", user = user, access = access, error = False)
app.run()Template file: profile.html
<body> <div> {% if error %} <h3>Hi {{user}}, {{access}} access denied</h3> {% else %} <h3>Hi {{user}}, you are logged in as {{access}}.</h3> {% endif %} </div></body>If the application is running locally on http://127.0.0.1:5000, then what will be rendered by the browser for URL, http://127.0.0.1:5000/profile/sumit?access=admin ?
Correct answer
A server, using the inbuilt http module of Python, is running for a directory My_app whose file structure and content of each file is given below.
Folder: My_app
My_app |_ home.html |_ index.html |_ main.htmlFile: home.html
<h1>Hello from Home!</h1>File: index.html
<h1>Hello from Index!</h1>File: main.html
<h1>Hello from Main!</h1>What will be rendered by the browser for the URL: http://localhost:8000 assuming that 8000 is the port of connection?
Correct answer
The lens of an HDD can read data on the rotating disk with the speed of 56,000 bits per second. The disk is designed such that 800 bits pass under the lens for every revolution of the disk, what should be the maximum speed of disk so that the lens does not miss any data?
70 RPM
100 RPM
4200 RPM
8000 RPM
Correct answer
4200 RPM
Consider a function remainder, and a set of test cases given below.
Filename: test_file.py
def remainder(numerator, denominator): rem = numerator % denominator return rem
def test_func0(): assert remainder(5,7) == 5
def test_function1(): assert remainder(20,4) == 0
def test_func2(): assert remainder(31,8) == 6
def test_function3(): assert remainder(19,3) == 1What will be the output on the terminal for the command pytest test_file.py -k func ?
Correct answer
Consider the following Python code snippet.
log.py
import loggingimport sys
logging.basicConfig(level=logging.CRITICAL, 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 24 ?
Correct answer
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()
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?
Correct answer
Consider the following flask application.
app.py
from flask import Flask, abort, requestapp = Flask(__name__)
data = {"CS2001":"DBMS","CS2003":"MAD-I","CS2006":"MAD-II"}@app.route('/login')def login(): username = request.args.get('uname') if username not in data: abort(400, "Bad Request: Invalid Username") return f'<h1>Welcome to {data[username]} course!</h1>'
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 ?
Correct answers
Which of the following statements is/are true about indexing?
Indexes are special lookup tables that the database search engine can use to speed up data retrieval.
Columns that are frequently manipulated should not be indexed.
Indexes enhance the performance even if the table is updated frequently.
Indexes should be avoided for tables that have frequent, large batch updates or insert operations.
Correct answers
Indexes are special lookup tables that the database search engine can use to speed up data retrieval.
Columns that are frequently manipulated should not be indexed.
Indexes should be avoided for tables that have frequent, large batch updates or insert operations.
Consider the following Model for Student.
class Student(db.Model): id = db.Column(db.Integer, primary_key=True) email = db.Column(db.String(100),unique=True,index=True) name = db.Column(db.String(100)) password = db.Column(db.String(100))Which of the following methods from the Flask-sqlalchemy query will behave the same as SQL query select * from Student where name='Ram'?
Correct answers
Consider the following flask application.
from flask import Flask, requestapp = Flask(__name__)
@app.route('/home')def home(): var_a = request.args.get('method') if var_a == "GET": return "Hello from GET method"
elif var_a == "POST": return "Hello from POST method"
else: return "Invalid Method"
app.run(debug=True)If the application is running locally on http://127.0.0.1:5000 then which of the following statements are correct?
Correct answers
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(10) == 100
@pytest.mark.marker2def testcase_2(): assert square(4) == 4
@pytest.mark.marker3def testcase_3(): assert square(5) == 25
@pytest.mark.marker4def testcase_4(): assert square(6) == 6On running this file on the terminal using pytest, the summary of the output is;
========= 1 failed, 3 deselected, 4 warnings in 0.04s =========What command will result into the outcome given above?
Correct answers
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).
Correct answers
Based on the above data, answer the given subquestions.
At what distance (kms) should the router be placed from the client so that round-trip latency of the network remains as low as 150 milliseconds?
8000 kilometers
7500 kilometers
4500 kilometers
3000 kilometers
Correct answer
4500 kilometers
Based on the above data, answer the given subquestions.
What will be the round-trip latency (milliseconds) of the network if the router is placed at exactly midway from the client and the server?
45
90
180
270
Correct answer
180