uiz Space

January 2024 term · Modern Application Development I · BSCS2003

Modern Application Development I Quiz 2: 24 March 2024 (January 2024 term)

The IIT Madras BS Modern Application Development I (MAD 1) Quiz 2 paper sat on 24 Mar 2024, in the January 2024 term: 16 questions for 50 marks in 120 minutes. Every question is below with its answer. Take it as a timed mock test to be marked, or read it through first.

Questions
16
Marks
50
Duration
120 min
MCQ
10
MSQ
6

Updated

Official paper: IIT M DIPLOMA AN EXAM QDD2 24 Mar 2024 · No negative marking.

Question 1

+2 marksOne correct option

Consider the following code.

python
from flask import Flask
app = Flask(__name__)
@app.route('/home')
def home1():
return "This is homepage 1"
@app.route('/home/')
def home2():
return "This is homepage 2"
@app.errorhandler(404)
def page_not_found(e):
return 'page not found'
app.run(debug=True)

If the flask application is running on http://127.0.0.1:5000, what will browser render for URL http://127.0.0.1:5000/home/

  1. A

    Page not found

  2. B

    This is homepage 1

  3. C

    This is homepage 2

  4. D

    Code will throw error

Show answer

Correct answer

  • C

    This is homepage 2

Question 2

+2 marksOne correct option

Consider the following Flask code snippet.

python
from flask import Flask, request
app = Flask(__name__)
@app.route('/greet/<name>')
def greet(name):
if name:
return f'<h1>Hi, Mr/Ms/ {name} welcome to flask</h1>'
else:
return f'<h1>Hi, Mr/Ms/ <Unknown> welcome to flask</h1>'
app.run(debug=True)

If the application is running on a local server for the URL: https://127.0.0.1:5000, what will the browser render for the URL, http://127.0.0.1:5000/greet/?

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

Correct answer

  • D

Question 3

+2 marksOne correct option

Consider the below statements about Cookies:
Statement 1: Cookies enable the web app to recognize the users
Statement 2: Cookies can include information about location, login data, and language etc., Which of the below is the correct option?

  1. A

    Statement 1 is correct and Statement 2 is incorrect

  2. B

    Statement 1 is incorrect and Statement 2 is correct

  3. C

    Both Statement 1 and Statement 2 are correct

  4. D

    Both Statement 1 and Statement 2 are incorrect

Show answer

Correct answer

  • C

    Both Statement 1 and Statement 2 are correct

Question 4

+2 marksOne correct option

Consider the below Flask code snippet:

python
from flask import Flask, jsonify
app = Flask(__name__)
@app.route('/api/courses')
def get_courses():
courses = [{'id': 'CS1001', 'name' : 'CT'}, {'id' : 'CS1002',
'name': 'PDSA'}]
return jsonify(courses)

If the application is running locally, what will be the status code and mimetype of the response for the URL, http:/127.0.0.1:5000/api/courses?

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

Correct answer

  • B

Question 5

+3 marksOne correct option

Consider a character set M, which consists of only those characters used in the statement, "sphinx of black quartz judge my vow" If this statement is to be saved in a document with minimum encoding, what will be the size of the document given that no other information or context is to be saved?

  1. A

    145 bits

  2. B

    245 bits

  3. C

    175 bits

  4. D

    256 bits

Show answer

Correct answer

  • C

    175 bits

Question 6

+3 marksOne correct option

Consider the following Python code snippet.

python
from string import Template
text = "The $color car is parked in front of the $building."
template = Template(text)
print(=== OUTPUT ===)

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

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

Correct answer

  • A

Question 7

+3 marksOne correct option
  1. A

    48 and 35

  2. B

    480 and 350

  3. C

    480 and 35000

  4. D

    48000 and 35000

Show answer

Correct answer

  • C

    480 and 35000

Question 8

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

Correct answer

  • D

Question 9

+3 marksOne correct option

Consider the following Python code snippet.

python
def modify(func):
def wrapper(name):
print("Before function execution")
result = func(name)
print("After function execution")
return result
return wrapper
@modify
def greet(name):
return f"Hello, {name}!"
print(greet("Ram"))

What will be the output of the code on the terminal?

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

Correct answer

  • A

Question 10

+4.5 marksOne correct option

Consider the following Python code snippet.

python
import logging
import sys
logging.basicConfig(level=logging.INFO,
format='%(levelname)s - %(message)s')
num1, num2 = int(sys.argv[1]), int(sys.argv[2])
logging.info("This operation checks factors")
if num1 % num2 == 0:
logging.debug(f"{num2} is a factor of {num1}")
else:
logging.warning(f"{num2} is not the factor of {num1}")

What will be the output of the above code on the terminal for the command:

bash
python log.py 25 5
  1. A
  2. B
  3. C
  4. D
Show answer

Correct answer

  • C

Question 11

+3 marksOne or more correct options

Consider the following flask application.

app.py

python
from flask import Flask, abort, request
app = Flask(__name__)
@app.route('/validate/<int:number>')
def validate_number(number):
if number % 2 == 0 and number % 3 == 1:
abort(400, "Bad Request: Invalid number provided")
return f'<h1>Valid Number: {number}</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 ?

Select all that apply.

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

Correct answers

  • C
  • D

Question 12

+3 marksOne or more correct options

Consider the following flask application.

app.py

python
from flask import Flask, abort, request
app = Flask(__name__)
@app.route('/process')
def process():
username = request.args.get('uname', 'MAD-I')
if username.isnumeric():
abort(400, "Bad Request: Numeric username provided")
return f'<h1>Valid Username: {username}</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 ?

Select all that apply.

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

Correct answers

  • B
  • C

Question 13

+3 marksOne or more correct options

Consider the following flask application.

app.py

python
from flask import Flask, abort, request
app = Flask(__name__)
data = {'MAD-I':'CS2003', 'MAD-II':'CS2004', 'Java':'CS2005'}
@app.route('/course/<course_name>')
def course(course_name):
course_id = request.args.get('id')
if course_name in data and course_id == data[course_name]:
return f'<h1>The Course ID for {course_name} is: {course_id}</h1>'
else:
abort(400, "Bad Request: Invalid data")
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 ?

Select all that apply.

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

Correct answers

  • B
  • D

Question 14

+4.5 marksOne or more correct options

Select all that apply.

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

Correct answers

  • C
  • D

Question 15

+4.5 marksOne or more correct options

Consider the following HTML document and select the correct option(s).

html
<!DOCTYPE html>
<html>
<head>
<title>Form Validation</title>
<script>
function validateForm() {
var username = document.forms["myForm"]["username"].value;
var password = document.forms["myForm"]["password"].value;
if (username == "") {
alert("Username must be filled out");
return false;
}
if (password.length < 8) {
alert("Password must be at least 8 characters long");
return false;
}
}
</script>
</head>
<body>
<form name="myForm" onsubmit="validateForm()">
<label for="username">Username:</label>
<input type="text" name="username">
<label for="password">Password:</label>
<input type="password" name="password" required>
<input type="submit" value="Submit">
</form>
</body>
</html>

Select all that apply.

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

Correct answers

  • B
  • C

Question 16

+4.5 marksOne or more correct options

Consider the following api resources created using flask_restful. Assume that the app is connected to the database and is running on one terminal. Select the correct option(s).

python
class TestApi(Resource):
def get(self, admin):
# retrieves admin data from database and returns it.
return {
"name": "mad1_admin",
"role": "admin",
}
def post(self):
# fetches user data from request body and stores in the
database.
return {
"message": "user added successfully"
}, 201
api.add_resource(TestApi, "/api/<string:admin>", "/<admin>",
"/user_data", "/")
app.run()

Select all that apply.

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

Correct answers

  • B
  • C
  • D