Quiz Space

May 2023 term · Modern Application Development I · BSCS2003

Modern Application Development I Quiz 2: 6 August 2023 (May 2023 term)

The IIT Madras BS Modern Application Development I (MAD 1) Quiz 2 paper sat on 6 Aug 2023, in the May 2023 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
11
MSQ
4
Written
1

Updated

Official paper: IIT M FOUNDATION AN2 EXAM QPF2 06 Aug 2023 · No negative marking.

Question 1

+2 marksOne correct option

Consider the following flask application and select the correct option if the application is running locally on http://127.0.0.1:5000.

python
from flask import Flask
app = Flask(__name__)
@app.route('/work')
@app.route('/home')
def my_task():
return "<h1>Hello! Reporting for my task</h1>"
app.run()
  1. A
  2. B
  3. C
  4. D
Show answer

Correct answer

  • C

Question 2

+2 marksOne correct option
  1. A

    OAS is a programming language used for building APIs.

  2. B

    OAS is a way to describe interfaces for building RESTful APIs.

  3. C

    OAS is a tool used for testing the performance of APIs.

  4. D

    OAS is a software library used for authenticating API requests.

Show answer

Correct answer

  • B

    OAS is a way to describe interfaces for building RESTful APIs.

Question 3

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

Correct answer

  • A

Question 4

+2 marksOne correct option

Consider the following view function.

python
@app.route('/student', methods = ['GET', 'POST'])
def show_student():
std = request.args
details = {
'Department': std['dept'],
'Course-level': std['level'],
'Course': std['course']
}
return details

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 5

+3 marksOne correct option

What will be the output of the following Python code snippet on the terminal?

python
def modify(n):
def modifier(n):
ser = [0,1]
for i in range(n-2):
new = ser[i]+ser[i+1]
ser.append(new)
print(ser)
return modifier
@modify
def list_num(n):
nums = []
for i in range(n):
nums.append(i+1)
print(nums)
list_num(10)
  1. A
  2. B
  3. C
  4. D
Show answer

Correct answer

  • D

Question 6

+3 marksOne correct option

Consider the following HTML Document file given below.

index.html

html
<!DOCTYPE html>
<html lang="en">
<head>
<title>Document</title>
<style>
input:invalid {
background: red;
}
input:valid {
background: green;
}
</style>
</head>
<body>
<form>
<label for="uname">Enter a valid e-mail:</label>
<input type="text" name="uname" minlength="8">
</form>
</body>
</html>

Suppose the index.html is rendered on the browser. What will be the background color of the input box when the user enters the name “madcourse.mail.com”?

  1. A

    red

  2. B

    white

  3. C

    green

  4. D

    insufficient information

Show answer

Correct answer

  • C

    green

Question 7

+3 marksOne correct option

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):
return {"greet":"Hello from GET Api!"}
def put(self):
return {"greet":"Hello from PUT Api!"}
api.add_resource(MyApi, '/api/get', '/api/put', '/api/post')
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 post
  4. curl http://127.0.0.1:5000/api/get -X put
  5. curl http://127.0.0.1:5000/api/put -X get
  6. curl http://127.0.0.1:5000/api/post -X get
  1. A

    Only 3

  2. B

    Only 3 and 4

  3. C

    Only 5 and 6

  4. D

    Only 3, 4, 5 and 6

Show answer

Correct answer

  • A

    Only 3

Question 8

+3 marksOne correct option

Consider the following code.

python
from flask import Flask
app = Flask(__name__)
@app.route('/')
def generate1():
return "This is generate1"
@app.route('//')
def generate2():
return "This is generate2"
@app.errorhandler(404)
def page_not_found(e):
# setting 404 status explicitly
return 'page not found'
app.run()

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//

  1. A

    Page not found

  2. B

    This is generate2

  3. C

    This is generate1

  4. D

    Code will throw error

Show answer

Correct answer

  • C

    This is generate1

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 parent can have multiple children 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 Parent(Base):
__tablename__ = "parent_table"
id = Column(Integer, primary_key=True)
# write your code 1 here
class Child(Base):
__tablename__ = "child_table"
id = Column(Integer, primary_key=True)
# write your code 2 here
  1. A
  2. B
  3. C
  4. D
Show answer

Correct answer

  • B

Question 10

+4.5 marksOne correct option

Consider the following models Brand and Cellphone corresponding to tables brand and cellphone in SQLite database.

python
class Brand(db.Model):
id = db.Column(db.Integer(), primary_key = True)
name = db.Column(db.String(), unique = True)
class Cellphone(db.Model):
id = db.Column(db.Integer(), primary_key = True)
name = db.Column(db.String(), unique = True)
brand = db.Column(db.Integer(), unique = True, db.ForeignKey("brand.id"))

Based on the model schemas, what relationship do the classes Brand and Cellphone share?

  1. A

    One-to-One

  2. B

    One-to-Many

  3. C

    Many-to-Many

  4. D

    The tables are not at all related

Show answer

Correct answer

  • A

    One-to-One

Question 11

+4.5 marksOne correct option

Consider the schema for the Class Student.

sql
CREATE TABLE "student" (
"s_id" INTEGER,
"roll_number" TEXT NOT NULL UNIQUE,
"first_name" TEXT NOT NULL,
"last_name" TEXT NOT NULL,
PRIMARY KEY("s_id" AUTOINCREMENT)
);

What will be the output of the flask_sqlalchemy command given below?

python
>>> s1 = Student(roll_number = M01, first_name = "Yash", last_name = "Raj")
>>> db.session.add(s1)
>>> s2 = Student(roll_number = M02, first_name = "Yash", last_name = "Maurya")
>>> db.session.add(s2)
>>> s3 = Student(roll_number = M03, first_name = "Ansh", last_name = "Raj")
>>> db.session.add(s3)
>>> db.session.commit()
>>> user1= Student.query.filter_by(first_name="Yash").first()
>>> user1.first_name= "Ansh"
>>> user1.last_name= "Maurya"
>>> db.session.commit()
>>> s1 = Student.query.all()
>>> for student in s1:
print(student.first_name)
print(student.last_name)
  1. A
  2. B
  3. C
  4. D
Show answer

Correct answer

  • B

Question 12

+4.5 marksOne or more correct options

Consider the following route in the flask for a signup page and select the correct option.

python
@app.route('/signup', methods=['GET', 'POST'])
def signup():
if request.method == 'GET':
return """<form action='/signup' method='POST'>
<label for='username'>Username</label>
<input type='text' name='username' required>
<label for='password'>Password</label>
<input type='text' name='password' required minlength="8">
<input type='submit' value='Submit'>
</form>
"""
if request.method == 'POST':
if request.form.get('username') is None:
return redirect(url_for(signup))
if request.form.get('password') is None:
return redirect(url_for(signup))
if len(request.form.get('password')) < 8:
return redirect(url_for(signup))
return f"<h1>Welcome, {request.form.get('username')}!</h1>"

Select all that apply.

  1. A

    The signup page is dynamically generated.

  2. B

    The signup page uses server-side rendering.

  3. C

    The signup page uses frontend validation only.

  4. D

    The signup page uses backend validation.

Show answer

Correct answers

  • A

    The signup page is dynamically generated.

  • B

    The signup page uses server-side rendering.

  • D

    The signup page uses backend validation.

Question 13

+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('/home')
def index():
return 'Mad-I welcomes you!'
@app.route('/user/<username>')
def profile(username):
return f'{username}\'s profile'
with app.test_request_context():
#== print statement ==#

Select all that apply.

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

Correct answers

  • B
  • D

Question 14

+3 marksOne or more correct options

Which of the following is/are valid JSON format.

Select all that apply.

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

Correct answers

  • A
  • B
  • D

Question 15

+3 marksOne or more correct options

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 "<html><body> <h1>Invalid number</h1></body></html>"
elif val['num'].isalpha()==True:
return "<html><body><h1>Enter a valid number</h1></body></html>"
else:
out = int(val['num']) * int(val['num'])
return f'<html><body> <h1>The output is {out}</h1></body></html>'
if(__name__ == "__main__"):
app.run(debug=True)

If this flask app is running locally on http://localhost:5000, then which of the following statements is/are correct?

Select all that apply.

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

Correct answers

  • B
  • C

Question 16

+3 marksWritten answer

Consider the following flask application.

python
from flask import Flask, redirect, url_for
app = Flask(__name__)
@app.route('/admin')
def hello_admin():
return 'Hello Admin'
@app.route('/guest/<guest>')
def hello_guest(guest):
return 'Hello ' +guest+ ' as Guest'
@app.route('/user/<name>')
def hello_user(name):
if name =='admin':
return redirect(url_for('hello_admin'))
else:
return redirect(url_for('hello_guest', guest = name))
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/user/admin?guest=appdev1

Show answer

Correct answer: Hello Admin