Home / Past papers / MAD1 Quiz 2 / this paper
What is the output after the following Python code is executed ? (Assume all entries are successfully committed to the database)

```python
class User(db.Model):
__tablename__ = "user"
id = db.Column(db.Integer, primary_key=True)
mail_id = db.Column(db.String, unique=True)
password = db.Column(db.String, nullable=False)
```
```python
>>> u1=User(mail_id='abc@gmail.com',password='12345')
>>> u2=User(mail_id='pxyz@gmail.com',password='abcd1234')
>>> u3=User(mail_id='lmn@gmail.com',password='54321')
>>> u4=User(mail_id='opqrst@gmail.com',password='xyz123')
>>> db.session.add_all([u1,u2,u3,u4])
>>> db.session.commit()
>>> result=User.query.filter(User.mail_id.like('p%')).all()
>>> print(len(result))
```
Table name: orders | id | cust_id | status | amount | |---|---|---|---| | 1 | C101 | PAID | 500 | | 2 | C102 | PENDING | 1200 | | 3 | C101 | PAID | 800 | | 4 | C103 | CANCELLED | 400 | | 5 | C102 | PAID | 1200 | Choose the correct SQLAlchemy statements that is similar to the SQL query: ```sql SELECT * FROM orders where status='PAID' and amount>500; ```

```python
order_records = db.session.query(Order).filter( \
Order.status == "PAID" and Order.amount > 500)
```
```python
order_records = db.session.query(Order) \
.filter(Order.status == "PAID") \
.filter(Order.amount > 500)
```
```python
order_records = db.session.query(Order).filter( \
Order.status == "PAID") and \
db.session.query(Order).filter(Order.amount > 500)
```
```python
order_records = db.session.query(Order.status == "PAID" and \
Order.amount > 500)
```
Based on the model schemas, what relationship do the classes Course and Enrollment share?```python
class Course(db.Model):
id = db.Column(db.Integer(), primary_key = True)
title = db.Column(db.String(), unique = True)
class Enrollment(db.Model):
id = db.Column(db.Integer(), primary_key = True)
student_id = db.Column(db.String(), nullable = False)
course_id = db.Column(db.Integer(), db.ForeignKey("course.id"))
```
What will be the output, when running the above code using the command "python decorator.py"?```python
def loggerDecorator(func):
def inner_wrapper():
print("Function execution started")
res1 = func()
res2 = func()
return res1, res2
return inner_wrapper
@loggerDecorator
def getData():
return "Data retrieved"
print(getData())
```
```
('Data retrieved', 'Data retrieved')
Function execution started
```
```text Function execution started Data retrieved Data retrieved ```

```
Function execution started
('Data retrieved', 'Data retrieved')
```
``` Data retrieved Data retrieved Function execution started ```

Ingredients: <ol> | Cooking Steps: <ol>

Ingredients: `<ul>` | Cooking Steps: `<ul>`

Ingredients: `<d1>` | Cooking Steps: `<u1>`

Ingredients: `<ul>` | Cooking Steps: `<ol>`

File name: app.py
```python
from jinja2 import Template
t = Template("""
{% for i in range(3) %}
{% set x = i %}
{% endfor %}
{{ x }}
""")
print(t.render())
```
What text output is generated when the command *python app.py* is executed?
If the application is running locally on http://127.0.0.1:5000, select the correct options.```python
from flask import Flask, abort, redirect, url_for
app = Flask(__name__)
@app.route('/course/<path:subject>')
def course(subject):
if "Python" in subject:
return "Welcome to Python course!"
else:
abort(404)
@app.route('/learn/<path:subject>')
def learn(subject):
if "Python" in subject:
return redirect(url_for('course', subject=subject))
else:
abort(404)
@app.errorhandler(404)
def not_found(error):
return "<h2>Course not available!</h2>"
app.run(debug=True)
```
For the URL: ``` http://127.0.0.1:5000/learn/web/Python?level=advanced ``` The browser will render: **Course not available!**

For the URL: ``` http://127.0.0.1:5000/course/ML/Python?topic=NLP ``` The browser will render: Welcome to Python course!

For the URL: ``` http://127.0.0.1:5000/learn/basics/Python?level=beginner ``` The browser will render: Welcome to Python course!

For the URL: ``` http://127.0.0.1:5000/course/Java/React?type=Framework ``` The browser will render: **Course not available!**
Which of the following statements about the template rendering behavior is correct?

```
my_app/
├── app.py
├── views/
│ └── index.html
├── templates/
│ ├── base.html
│ └── page.html
└── my_templates/
├── public/
│ └── home.html
└── private/
└── dashboard.html
```
app.py:
```python
from flask import Flask, render_template
app = Flask(__name__, template_folder='my_templates')
@app.route('/')
def home():
return render_template('public/home.html')
@app.route('/dashboard')
def dashboard():
return render_template('private/dashboard.html')
@app.route('/view')
def view():
return render_template('index.html')
@app.route('/page')
def page():
return render_template('page.html')
if __name__ == '__main__':
app.run(debug=True)
```
and 
templates/ ``` my_templates/ ```
and
routes work, while
and
routes fail with
Error/dashboard /view The image contains a single, small, blurry, diagonal line. It appears to be a checkmark or a slash, but its exact nature is unclear due to the low resolution. /page TemplateNotFound
and
routes work, while
and
fail with
ErrorThe image contains a single, small, blurry, diagonal line. It appears to be a checkmark or a slash, but its exact nature is unclear due to the low resolution. /dashboard /view /page TemplateNotFound

``` curl -X PUT -d "status=active&role=admin" https://api/users/update ```
What will be the response?File name: app.py
```python
from flask_restful import reqparse, Resource, Api
from flask import Flask
parser = reqparse.RequestParser()
parser.add_argument("n", type=int, required=True)
app = Flask(__name__)
api = Api(app)
class MyResponse(Resource):
def post(self):
args = parser.parse_args()
return args
api.add_resource(MyResponse, "/")
app.run(debug=True)
```
Assume that the Flask app is running at http://127.0.0.1:5000. The client sends the below CURL request in the git bash terminal.
```bash
curl -X POST http://127.0.0.1:5000 -H "Content-Type: application/json" -d "{\"n\":3}"
```
The above flask app is running on "http://127.0.0.1:5000". Which of the following commands will return a runtime error?```python
from flask import Flask
from flask_restful import Resource, Api
app = Flask(__name__)
api = Api(app)
class UserResource(Resource):
def get(self):
return {"status": "GET request"}, 200
def post(self, user_id):
return {"status": "POST request", "user_id": user_id}, 201
api.add_resource(UserResource, "/users", "/users/<int:user_id>")
if __name__ == "__main__":
app.run(debug=True)
```
``` curl http://127.0.0.1:5000/users/5001 -X GET ```

``` curl http://127.0.0.1:5000/users/5001 -X POST ```

``` curl http://127.0.0.1:5000/users -X POST ```

``` curl http://127.0.0.1:5000/users -X GET ```