Quiz Space

May 2022 term · Modern Application Development I · BSCS2003

MAD 1 End Term: 7 August 2022 (May 2022 term)

The IIT Madras BS Modern Application Development I (MAD 1) End Term paper sat on 7 Aug 2022, in the May 2022 term: 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
25
MSQ
6
Numerical
1

Updated

Official paper: IIT M FOUNDATION DIPLOMA ENDTERM QPD1 07 Aug 2022 IBA NS · No negative marking.

Question 1

+2 marksOne correct option

Which of the following correctly represents the components of the given URL?

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

Correct answer

  • C

Question 2

+2 marksOne correct option

Consider the following flask app and an HTML file in templates folder:

Python file: app.py

python
from flask import Flask, render_template
app = Flask(__name__)
my_list = ['Web development','onlinedegree','cs2003',
'MAD-I','Data_science']
@app.route('/')
def render():
return render_template('index.html', my_list = my_list)
app.run(debug = True)

Template file:

html
<!DOCTYPE html>
<head>
<style>
body{width: 200px;
border: 2px solid black}
#one{color:red;}
#two{color:blue;}
</style>
</head>
<body>
{% for item in my_list %}
{% set Length = item|length %}
{% if Length%2 == 0 %}
<h3 id = "one">{{ item }}</h3>
{% else %}
<h3 id = "two">{{ item }}</h3>
{% endif %}
{% endfor %}
</body>

If the above flask app is running locally on http://127.0.0.1:5000/, what will be rendered by the browser for the base URL?

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

Correct answer

  • D

Question 3

+2 marksOne correct option

Consider the flask code given below.

Python file: app.py

python
from flask import Flask, jsonify, request
app = Flask(__name__)
my_shops= [
{
'name of the shop' : 'Grocery',
'items' : [
{
'item1' : 'Toothpaste',
'item2' : 'Snacks',
'item3' : 'Biscuits',
'item4' : 'Soaps'
}
]
}
]
@app.route('/')
def show_shop():
return jsonify({"shops" : my_shops})
#======================
CODE HERE
#======================
if __name__ == '__main__':
app.run()

Which of the following code snippets must be added in the given space of above application, in order to create a new shop in ‘my_shops’ list on the server side apart from the existing one?

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

Correct answer

  • B

Question 4

+2 marksOne correct option

A table ‘person’ is created in the database using model class “Person” with fields and their properties given in the table below.

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

Correct answer

  • B

Question 5

+2 marksOne correct option

A flask app and a template files are given below.

Python file: app.py

python
from flask import Flask, render_template
app = Flask(__name__)
@app.route('/home')
def HomePage():
return "Welcome, folks! This is the Home Page!"
@app.route('/about')
def AboutPage():
users = [
{"user":"Shobhit","gender" : "Male" , "age" : 23, "score": 90},
{"user":"Deepak", "gender" : "Male" , "age" : 17, "score": 88},
{"user":"Nikita", "gender" : "Female" , "age" : 20, "score": 87}
]
return render_template('home.html', condition=True, users=users)
if __name__ == "__main__":
app.run(debug=True)

Templates file: home.html

html
<!DOCTYPE html>
<html>
<body>
<p><a href="{{ url_for('HomePage') }}">Go back to home page?</a></p>
<h2>About page</h2>
{% if condition %}
<h3> You are landed on about page.</h3>
{% for user in users %}
<ul>
<li>Username : {{user.user}}, Age : {{user.age}}, Gender :
{{user.gender}}, Score : {{user.score}}</li>
</ul>
{% endfor %}
{% else %}
<h3> Please Go back.</h3>
{% endif %}
</body>
</html>

If the above flask application is running locally on “http://127.0.0.1:5000”, which of the following statement is true?

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

Correct answer

  • B

Question 6

+2 marksOne correct option

An HTML document is given below.

html
<!DOCTYPE html>
<html>
<body>
<h1 id="id1">Welcome to IITM</h1>
<h3 class="class1">Welcome to the world's first online degree
program.</h3>
<a href="">Go back to main link</a>
<p class="class1">Lorem ipsum dolor sit amet consectetur
adipisicing elit. Earum, rerum?</p>
<p class="class1">Have you enrolled in BSC in Data science
and Programming? </p>
<p id="id2">Go to the IITM online degree website and enroll
now!</p>
</body>
</html>

Suppose, if we want to give red color to the text within the heading element having id="id1” and green color to the text within the heading element having class="class1”, what will be the correct way to do that?

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

Correct answer

  • C

Question 7

+2 marksOne correct option

Consider the following HTML document with internal CSS.

html
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
*{
margin: 0px;
width: 253px;
}
div{
margin: 10px;
padding: 20px;
border-style: dotted;
border-width: 10px;
font-size: 30px;
color: blue;
background-color: pink;
border-color: red;
}
</style>
<title>End Sem</title>
</head>
<body>
<div>This is my content</div>
<div>Another content</div>
</body>
</html>

How will the browser render the above HTML document?

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

Correct answer

  • D

Question 8

+2 marksOne or more correct options

Select all that apply.

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

Correct answers

  • C
  • D

Question 9

+3 marksOne correct option

How will the browser render the output of the following Python code snippet?

python
from jinja2 import Template
styles=[
'.text{color: purple}\n #heading{color:red}\n #subhead{color:blue}',
'.text{color: purple}\n #subhead{color:green}\n #main{color:blue}',
'.text{color: purple}\n #main{color:red}\n #heading{color:blue}'
]
template = """
<!DOCTYPE html>
<style>
div{border: 2px solid black;
width: 300px;
background-color: rgb(247, 247, 230)}
{{styles[0]}}
</style>
<body>
<div>
<h2 style="color:brown;" class="text" id="heading">
Programming Degree</h2>
<h3 class="text" id="subhead">Modern Application 1</h3>
<p class="text" id="main">This is a course on Application
Development</p>
</div>
</body>
"""
test_render = Template(template)
output = test_render.render(styles = styles)
print(output)
  1. A
  2. B
  3. C
  4. D
Show answer

Correct answer

  • D

Question 10

+3 marksOne correct option

What will be the output of the following python code if method test_request_context() allows flask app to print statements on the terminal?

python
from flask import Flask, url_for
app = Flask(__name__)
@app.route('/')
def home():
return 'base url'
@app.route('/subscribe')
def subscribe():
return 'Please subscribe to this page.'
@app.route('/new_course/<coursename>')
def course(coursename):
return f'The course {coursename} gives basics of web development.'
with app.test_request_context():
print(url_for('home'))
print(url_for('subscribe'))
print(url_for('subscribe', username = 'user_one'))
print(url_for('course', coursename = 'MAD_I'))
  1. A
  2. B
  3. C
  4. D
Show answer

Correct answer

  • C

Question 11

+3 marksOne correct option

An internet connection with certain bandwidth is able to serve 10,000 requests of 150 Kilobytes each. What should be the increase in bandwidth (in Gbps) if this internet connection is to handle 12,500 requests of 180 Kilobytes each? (Use relations: 1 Byte = 8 bits, 1 MB = 1000 B, 1 GB = 1000 M and so on)

  1. A

    600

  2. B

    6

  3. C

    0.6

  4. D

    12

Show answer

Correct answer

  • B

    6

Question 12

+3 marksOne correct option

Consider the code snippet given below.

Python file: test_app.py

python
import pytest
@pytest.fixture
def items():
return "Books"
@pytest.fixture
def order():
return "Pens"
@pytest.fixture
def order_items(order, items):
return [order, items]
@pytest.fixture
def expected_list():
return ["Books", "Pencils", "Pens"]
def test_1(order_items, expected_list):
order_items.append("Pencils")
assert order_items == expected_list
def test_2(order_items):
order_items.append("Pencils")
assert order_items == ["Pens", "Books", "Pencils"]

Which of the following statement is true about the above code snippet?

  1. A

    After running pytest, test_1 will fail, whereas test_2 will pass.

  2. B

    After running pytest, test_2 will fail, whereas test_1 will pass.

  3. C

    Both the test cases, test_1 and test_2 will pass successfully.

  4. D

    Both the test cases, test_1 and test_2 will fail.

Show answer

Correct answer

  • A

    After running pytest, test_1 will fail, whereas test_2 will pass.

Question 13

+3 marksOne correct option

Consider the Python code snippet given below.

Python file: app.py

python
from flask import Flask, request
from flask_restful import Api, Resource, reqparse
app = Flask(__name__)
api = Api(app)
class Add(Resource):
def post(self):
data_args = reqparse.RequestParser()
data_args.add_argument('Name', help='Name is required',
required =True)
data_args.add_argument('Age', help='Age is required',
required =True)
args = data_args.parse_args()
return { "Your Name": args['Name'], "Your Age" : args['Age']}
api.add_resource(Add, '/add')
if __name__ == '__main__':
app.run(debug=True)

If this flask application is running on http://127.0.0.1:5000, which of the following is the correct output when a POST request is sent to URL "http://127.0.0.1:5000/add"?

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

Correct answer

  • C

Question 14

+3 marksOne correct option

Consider the Python code given below.

python
import pytest
@pytest.fixture
def first_entry():
return "Apple"
@pytest.fixture
def order(first_entry):
return [first_entry]
def test_string(order):
order.append("Kiwi")
assert order == ["Banana", "Apple"]
def test_int(order):
order.append("Banana")
assert order == ["Banana", "Apple", "Kiwi"]

Which of the following statement is true?

  1. A

    After running pytest, both test cases will pass successfuly.

  2. B

    After running pytest, the first test case will fail, whereas the second test case will pass.

  3. C

    After running pytest, both test cases will show a failure report.

  4. D

    None of these

Show answer

Correct answer

  • C

    After running pytest, both test cases will show a failure report.

Question 15

+3 marksOne correct option

Consider the flask app given below.

python
from flask import Flask, abort
from flask_restful import Resource, Api
app = Flask(__name__)
api = Api(app)
item_list=[{"item1": "Cloths"},
{"item2" : "Shoes"},
{"item3" : "Sunglasses"}]
class ItemList(Resource):
def get(self, item_no, item_name):
this_item = {'item'+item_no : item_name}
if this_item in item_list:
return item_list, 200
else:
abort('400')
def post(self, item_no, item_name):
my_item = {'item'+item_no : item_name}
item_list.append(my_item)
return my_item, 201
api.add_resource(ItemList, '/items/<item_no>/<item_name>')
app.run(debug=True)

If the above flask application is running locally on “http://127.0.0.1:5000”, what will be the output of a GET request sent to the URL: ‘http://127.0.0.1:5000/items/4/watch’ just after a POST request that is sent on the same URL?

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

Correct answer

  • C

Question 16

+3 marksOne correct option

Consider the following flask application.

python
from flask import Flask, render_template
app=Flask(__name__)
@app.route('/')
def home():
my_items = ['Cake', 'Apple', 'Ice Cream', 'DarkChocolate',
'Donut', 'Grape']
l1 = []
for i in range(len(my_items)):
if i>2:
l1.append(my_items[i])
return render_template('index.html', list=l1)
app.run(debug=True)

Template File - index.html

html
{% macro display(list) %}
{% for item in list %}
<p>{{ item }}</p>
{% endfor %}
{% endmacro %}
<html>
<body>
{{ display(list) }}
</body>
</html>

suppose the application is running locally on the ‘http://127.0.0.1:5000', then what will be rendered by the browser?

  1. A

    Cake
    Apple
    Ice Cream

  2. B

    Cake
    Apple
    Ice Cream
    DarkChocolate
    Donut
    Grape

  3. C

    DarkChocolate
    Donut
    Grape

  4. D

    Ice Cream
    DarkChocolate
    Donut
    Grape

Show answer

Correct answer

  • C

    DarkChocolate
    Donut
    Grape

Question 17

+3 marksOne correct option

Consider the following Python code snippets.

File 1: main.py

python
import sys
from new import fun
a = sys.argv[1]
b = sys.argv[2]
c = sys.argv[3]
result = fun(a, b, c)
print(result + " is greater")

File 2: new.py

python
def fun(num1,num2,num3):
if (num1 > num2) and (num1 > num3):
return num1
elif (num2 > num1) and (num2 > num3):
return num2
else:
return num3

suppose the main.py file is executed in the terminal. What will be the output?

bash
python main.py
python main.py 8 10 5
  1. A

    IndexError: list index out of range
    NameError: name 'fun' is not defined

  2. B

    3 is greater
    NameError: name 'fun' is not defined

  3. C

    IndexError: list index out of range
    10 is greater

  4. D

    NameError: name 'fun' is not defined
    8 is greater

Show answer

Correct answer

  • C

    IndexError: list index out of range
    10 is greater

Question 18

+3 marksOne correct option

Consider a server that has an Intel i5 processor, 64 GB RAM, 1 TB Hard disk with 3 Gbps network connection. If a client accesses a web page, it requires 1.5 MB. Calculate the maximum number of such requests per second the server can handle. (Use relations: 1 Byte = 8 bits, 1 MB = 1000 B, 1 GB = 1000 M and so on).

  1. A

    25

  2. B

    32

  3. C

    250

  4. D

    200

Show answer

Correct answer

  • C

    250

Question 19

+3 marksOne or more correct options

Consider the following Python code snippet.

python
from flask import Flask, abort, redirect, url_for, render_template
app = Flask(__name__)
weekday_users = ['user_1','user_3','user_4','user_6','user_7']
weekend_users = ['user_2','user_5']
@app.route('/weekday/<username>')
def user_weekday(username):
if username in weekday_users:
return redirect(url_for('login', username = username))
else:
abort(401)
@app.route('/weekend/<username>')
def user_weekend(username):
if username in weekend_users:
return redirect(url_for('login', username = username))
else:
abort(401)
@app.route('/login/<username>')
def login(username):
return f"<h2>Correct User Found! {username}</h2>"
@app.errorhandler(401)
def page_not_found(error):
return "<h2>You are not authorized for this day.</h2>", 401
app.run()

If the above flask app is running locally on “http://127.0.0.1:5000”, Which of the following statements is/are correct?

Select all that apply.

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

Correct answers

  • A
  • C

Question 20

+3 marksOne or more correct options

Consider the code given below.

python
from flask import Flask, request
from flask_restful import Api, Resource, reqparse
app = Flask(__name__)
api = Api(app)
Mytasks = {
1: {"mytask": "Studying"},
2: {"mytask": "Exercise"},
3: {"mytask": "Eating"},
4: {"mytask": "Sleeping"}
}
class Display(Resource):
def get(self):
return Mytasks
class DisplayAll(Resource):
def get(self, MytaskList_id):
return Mytasks[MytaskList_id]
def post(self, MytaskList_id):
data_args = reqparse.RequestParser()
data_args.add_argument("mytask",help='This is required
field', required =True)
args = data_args.parse_args()
Mytasks[MytaskList_id] = {"mytask" : args["mytask"]}
return Mytasks[MytaskList_id]
api.add_resource(Display, '/mytask')
api.add_resource(DisplayAll, '/task/<int:MytaskList_id>')
if __name__ == '__main__':
app.run(debug=True)

If the above flask application is running locally on “http://127.0.0.1:5000”, which of the following statements is/are true?

Select all that apply.

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

Correct answers

  • A
  • B
  • C

Question 21

+4.5 marksNumerical answer

What will be the decimal representation of binary number 0101011000000112?

Show answer

Correct answer: 11011

Question 22

+4.5 marksOne correct option

A machine takes a minimum of 100 seconds to sort 500 entries in a database. What will be the approximate minimum time taken by the machine to sort 1200 entries if the sorting method employs an algorithm with time complexity of O(nlog(n)). Where “n” is the number of entries?

  1. A

    173 seconds

  2. B

    273 seconds

  3. C

    373 seconds

  4. D

    473 seconds

Show answer

Correct answer

  • B

    273 seconds

Question 23

+4.5 marksOne correct option

The speed vs. throughput characteristics of a typical HDD is shown in the figure below. If this HDD is to be used as a replacement of an SSD whose read/write speed is 450 MB/s. At what speed (in RPM) should the disk of HDD rotate with to deliver the same performance as that of the SSD?

  1. A

    3600 RPM

  2. B

    7200 RPM

  3. C

    16,200 RPM

  4. D

    28,800 RPM

Show answer

Correct answer

  • D

    28,800 RPM

Question 24

+4.5 marksOne correct option

Consider the following Flask app and an HTML file.

Flask app: app.py

python
from flask import Flask, render_template, request
app = Flask(__name__)
users = {
'3':{'name': 'Ram', 'Designation': 'Teacher'},
'2':{'name': 'Dilip', 'Designation': 'student'},
'5':{'name': 'Sonu', 'Designation': 'computer operator'},
'1':{'name':'Guru', 'Designation': 'clerk'}
}
@app.route('/')
def country():
id = request.args.get('id')
authenticated_users_id = [3, 2, 5]
user = users.get(id)
name = user.get('name') if user is not None else None
Designation = user.get('Designation') if user is not None else
None
user = {'is_authenticated': False, 'name': name, 'Designation':
Designation}
if int(id) in authenticated_users_id:
user['is_authenticated'] = True
return render_template('index.html', data = user)
if int(id) not in authenticated_users_id:
user['is_authenticated'] = False
return render_template('index.html', data = user)
app.run(debug = True)

HTML File: index.html

html
<!DOCTYPE html>
<html lang="en">
<head>
<title>Document</title>
</head>
<body>
{% if data.name == None %}
User not found
{% elif data.is_authenticated == True %}
Hello {{data.name}} you can enter into this site:
{{data.Designation}}
{% else %}
Hello {{data.name}} you have no access to this site:
{{data.Designation}}
{% endif %}
</body>
</html>

Suppose the application is running locally on the ‘http://127.0.0.1:5000', then what will be rendered by the browser for ‘http://127.0.0.1:5000/?id=5', http://127.0.0.1:5000/?id=1’ and ‘http://127.0.0.1:5000/?id=4' respectively?

  1. A

    Hello Sonu you can enter into this site: computer operator
    Hello Guru you have no access to this site: clerk
    User not found

  2. B

    Hello Ram you can enter into this site: Teacher
    Hello Guru you have no access to this site: Student
    Hello Sonu you can enter into this site: computer operator

  3. C

    User not found
    Hello Dilip you have no access to this site: Student
    Hello Sonu you can enter into this site: computer operator

  4. D

    Hello Ram you can enter into this site: Teacher
    Hello Dilip you have no access to this site: Student
    User not found

Show answer

Correct answer

  • A

    Hello Sonu you can enter into this site: computer operator
    Hello Guru you have no access to this site: clerk
    User not found

Question 25

+4.5 marksOne correct option

Consider the following Python code snippet.

python
from jinja2 import Template
temp = """{% set numbers = studs | map(attribute = "mark") | list %}
{{numbers | min}} {{numbers | max}}"""
studs = [
{"stud_name":"Reeta","mark":"92"},
{"stud_name":"Veena","mark":"88"},
{"stud_name":"Meena","mark":"62"},
{"stud_name":"uma","mark":"98"}
]
t1 = """{% for i in studs -%}
{{i}}
{%- endfor%}"""
output = Template(temp)
out = Template(t1)
print(output.render(studs = studs))
print(out.render(studs = studs))

What will be the output of the above program?

  1. A

    98 62
    {'stud_name': 'Reeta', 'mark': '92'}
    {'stud_name': 'Veena', 'mark': '88'}
    {'stud_name': 'Meena', 'mark': '62'}
    {'stud_name': 'uma', 'mark': '98'}

  2. B

    62 98
    {'stud_name': 'Reeta', 'mark': '92'}{'stud_name': 'Veena', 'mark': '88'}{'stud_name':
    'Meena', 'mark': '62'}{'stud_name': 'uma', 'mark': '98'}

  3. C

    62 98
    {'stud_name': 'uma', 'mark': '92'}
    {'stud_name': 'Meena', 'mark': '88'}
    {'stud_name': 'Veena', 'mark': '62'}
    {'stud_name': 'Reeta', 'mark': '98'}

  4. D

    98 62
    {'stud_name': 'uma', 'mark': '92'}{'stud_name': 'Meena', 'mark': '88'}{'stud_name':
    'Veena', 'mark': '62'}{'stud_name': 'Reeta', 'mark': '98'}

Show answer

Correct answer

  • B

    62 98
    {'stud_name': 'Reeta', 'mark': '92'}{'stud_name': 'Veena', 'mark': '88'}{'stud_name':
    'Meena', 'mark': '62'}{'stud_name': 'uma', 'mark': '98'}

Question 26

+4.5 marksOne correct option

Consider the following table “newtable” in SQLite database.

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

Correct answer

  • B

Question 27

+4.5 marksOne correct option

Consider the following Python snippet.

  1. A

    Introduction
    Code

  2. B

    Java is a powerful general purpose …
    Java works on different platforms(windows)

  3. C

    Introduction - Java is a powerful general purpose …
    learn python - Python is a powerful general purpose …
    Basics - Java works on different platforms(windows)

  4. D

    Introduction
    Basics

Show answer

Correct answer

  • D

    Introduction
    Basics

Question 28

+4.5 marksOne or more correct options

Consider the HTML code given below.

To obtain the output as given in figure above, which of the following snippets of CSS code must be used?

Select all that apply.

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

Correct answers

  • B
  • D

Question 29

+3 marksOne or more correct options

Consider the following model classes “State” and “City” corresponding to tables “state” and “city” respectively in the SQLite database.

python
class State(db.Model):
state_id = db.Column(db.Integer(), primary_key = True)
state_name = db.Column(db.String(50), nullable = False)
cities = db.relationship("City", backref = "stateof")
class City(db.Model):
city_id = db.Column(db.Integer(), primary_key = True)
city_name = db.Column(db.String(50), nullable = False)
state = db.Column(db.Integer(), db.ForeignKey("state.state_id"))

Based on the above data, answer the given subquestions.

Select all that apply.

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

Correct answers

  • B
  • C

Question 30

+3 marksOne or more correct options

Consider the following model classes “State” and “City” corresponding to tables “state” and “city” respectively in the SQLite database.

python
class State(db.Model):
state_id = db.Column(db.Integer(), primary_key = True)
state_name = db.Column(db.String(50), nullable = False)
cities = db.relationship("City", backref = "stateof")
class City(db.Model):
city_id = db.Column(db.Integer(), primary_key = True)
city_name = db.Column(db.String(50), nullable = False)
state = db.Column(db.Integer(), db.ForeignKey("state.state_id"))

Based on the above data, answer the given subquestions.

If “s1” and “c1” are existing objects in the tables “state” and “city” respectively where:

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 31

+3 marksOne correct option

Consider the following resource API for the employee information given below and answer the given subquestions.

python
from flask import Flask
from flask_restful import Resource, Api, reqparse, fields, marshal_with
app = Flask('__main__')
api = Api(app)
parser = reqparse.RequestParser()
parser.add_argument("first_name")
parser.add_argument("last_name")
parser.add_argument("role")
parser.add_argument("salary", type=int, help='Salary must be an integer')
out_fields_1 = {"first_name": fields.String,"role": fields.String}
out_fields_2 = {"first_name": fields.String,"last_name": fields.String}
out_fields_3 = {"first_name": fields.String, "salary": fields.Integer}
class MyApi(Resource):
@marshal_with(out_fields_2)
def get(self):
info = parser.parse_args()
return info
@marshal_with(out_fields_1)
def post(self):
info = parser.parse_args()
return info
@marshal_with(out_fields_3)
def put(self):
info = parser.parse_args()
return info
api.add_resource(MyApi, '/myinfo')
app.run(debug = True)
  1. A
  2. B
  3. C
  4. D
Show answer

Correct answer

  • C

Question 32

+3 marksOne correct option

Consider the following resource API for the employee information given below and answer the given subquestions.

python
from flask import Flask
from flask_restful import Resource, Api, reqparse, fields, marshal_with
app = Flask('__main__')
api = Api(app)
parser = reqparse.RequestParser()
parser.add_argument("first_name")
parser.add_argument("last_name")
parser.add_argument("role")
parser.add_argument("salary", type=int, help='Salary must be an integer')
out_fields_1 = {"first_name": fields.String,"role": fields.String}
out_fields_2 = {"first_name": fields.String,"last_name": fields.String}
out_fields_3 = {"first_name": fields.String, "salary": fields.Integer}
class MyApi(Resource):
@marshal_with(out_fields_2)
def get(self):
info = parser.parse_args()
return info
@marshal_with(out_fields_1)
def post(self):
info = parser.parse_args()
return info
@marshal_with(out_fields_3)
def put(self):
info = parser.parse_args()
return info
api.add_resource(MyApi, '/myinfo')
app.run(debug = True)

If the flask application is running locally on URL “http://127.0.0.1:5000/myinfo”, what will be the output of the following Python code snippet?

python
import requests
data = {"first_name":"Rajnish",
"last_name":"Dey",
"role":"Manager",
"salary":"10 thousand"}
response = requests.put('http://127.0.0.1:5000/myinfo', data = data)
print(response.json())
  1. A
  2. B
  3. C
  4. D
Show answer

Correct answer

  • D