Quiz Space

MAD 1 Quiz 2: 3 December 2023 (September 2023 term)

Question 1

+4.5 marksOne correct option

Consider the schema for the 'student' table created in SQLite database using flask-sqlalchemy.

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 = "John", last_name = "Doe")
>>> db.session.add(s1)
>>> s2 = Student(roll_number = "M02", first_name = "John", last_name = "Luther")
>>> db.session.add(s2)
>>> s3 = Student(roll_number = "M03", first_name = "Harry", last_name = "Doe")
>>> db.session.add(s3)
>>> db.session.commit()
>>> user1= Student.query.filter_by(first_name="John").first()
>>> user1.first_name= "Harry"
>>> user1.last_name= "Luther"
>>> 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

Question 2

+4.5 marksOne correct option

Consider the following flask application.

python
from flask import Flask, abort
app = Flask(__name__)
users = ["admin", "user_1", "user_2", "user_3"]
@app.route('/home/<string:username>', methods = ['POST'])
def home(username):
if username in users:
return f"<h1>Hello {username}, Welcome!</h1>"
else:
abort(404)
@app.errorhandler(404)
def user_error_1(error):
return "<h1>The user you are looking for is invalid.</h1>"
@app.errorhandler(405)
def user_error_2(error):
return "<h1>Please check the web request.</h1>"
app.run()

If the application is running locally on http://127.0.0.1:5000. What will be rendered on the browser for url http://127.0.0.1:5000/home/user_4 ?

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

Question 3

+3 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 Student Data'
@app.route('/student/<student_name>/<int:student_id>')
def profile(student_name,student_id):
return f'Student Name:{student_name},Student ID:{student_id}'
with app.test_request_context():
#== print statement ==#

Select all that apply.

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

13 more questions in this paper

Sign in with Google — it is free — to see every question with its answer and explanation, practise it in learning mode, or take it as a timed mock test.

More on the MAD 1 Quiz 2 3 Dec 2023 paper

The IIT Madras BS Modern Application Development I (MAD 1) Quiz 2 paper sat on 3 Dec 2023, in the September 2023 term: 16 questions for 50 marks in 120 minutes. The first 3 questions are below. Sign in with Google — it is free — to see the whole paper with its answers and explanations, in learning mode or as a timed mock test.

FeatureMAD 1 Quiz 2 3 Dec 2023 at a glance
TermSeptember 2023 term
SubjectModern Application Development I
Course codeBSCS2003
Questions16
Marks50
Duration120 min
MCQ11
MSQ5
Official paperIIT M DIPLOMA AN2 EXAM QDD2 03 Dec 2023
Negative markingNo negative marking.
Updated

Same Quiz 2, other subjects

More MAD 1