Home / MAD1 / Week 2 / Real questions
60 questions pulled from past papers whose wording matches this week's topics, newest first, duplicates removed. Pick your answers, then press Check answers. Figures and answer keys are the originals.
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"))
```
Ingredients: <ol> | Cooking Steps: <ol>

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

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

Ingredients: `<ul>` | Cooking Steps: `<ol>`
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
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 ```
What will be rendered by the browser?File name: home.html
```html
<!DOCTYPE html>
<html lang="en">
<style>
div{color:green}
.cdiv{color:red}
#div1{color:blue}
</style>
<body>
<div id="div1" class="cdiv">IITM BS Degree in Data Science</div>
</body>
</html>
```
IITM BS Degree in Data Science

IITM BS Degree in Data Science

IITM BS Degree in Data Science

1. IITM BS Degree in Data Science

Block: `<span>` | Inline: `<div>`

Block: `<div>` | Inline: `<a>`

Block: `<h1>` | Inline: `<p>`

Block: `<span>` | Inline: `<h5>`
Which of the following code snippets should be placed at
such that the output generated in the terminal when rendered will be as shown below?

```python
from jinja2 import Template
output = """
<!DOCTYPE html>
<html>
<body>
<ul>
<!--Missing Jinja2 implementation-->
</ul>
</body>
</html>
"""
l = [6, 8, 5, 2, 4]
t = Template(output)
output = t.render(sl=l)
print(output)
```
```html
<!--Missing Jinja2 implementation-->
```
- 8
- 6
- 5
- 4
- 2
```html
{%for item in sl|sort(reverse=True)%}
<li>{{item}}</li>
{%endfor%}
```
```html
{%for item in sl%}
<li>{{item}}</li>
{%endfor%}
```
```html
{%for item in sl|sort%}
<li>{{item}}</li>
{%endfor%}
```
```
{%for item in sl.sort()%}
<li>{{item}}</li>
{%endfor%}
```
Which of the following will be the correct rendered output ?```html
<!DOCTYPE html>
<html>
<head>
<style>
.container{
display: flex;
width: 250px;
border: 2px solid black;
}
.box{
width: 80px;
height: 40px;
border: 1px solid blue;
margin: 5px;
text-align: center;
}
</style>
</head>
<body>
<div class="container">
<div class="box">1</div>
<div class="box">2</div>
<div class="box">3</div>
</div>
</body>
</html>
```
This is a diagram showing three rectangular boxes stacked vertically within a larger outer rectangle. Each inner box is outlined in blue and contains a single number. - The top box is labeled "1". - The middle box is labeled "2". - The bottom box is labeled "3".

This is a diagram of a rectangle with a nested rectangle. The outer rectangle is black. The inner rectangle is blue. Inside the inner rectangle, the text "1 2 3" is displayed.

This is a diagram of three rectangular boxes arranged horizontally, each containing a number. - The first box on the left contains the number "1". - The second box in the middle contains the number "2". - The third box on the right contains the number "3". All boxes are outlined with a dark blue border, and the vertical lines separating the boxes are also dark blue.

The image displays a diagram with a black rectangular outer border. Inside this border, there are three smaller, identical rectangular boxes arranged horizontally. Each of these inner boxes has a blue border. The boxes are labeled with numbers: "1" in the leftmost box, "2" in the middle box, and "3" in the rightmost box. There is a small gap between each of the inner boxes.

| Column A | Column B | |---|---| | 1. ftp | A. Web domain | | 2. 127.0.0.1 | B. Protocol | | 3. `<b></b>` | C. Decorator | | 4. seek.onlinedegree.iitm.ac.in | D. Loop back IP | | 5. @app.route | E. HTML element |
with below data.
Which of the following SQL Alchemy statements is used to count the number of students registered for
?CourseRegistrations | ID | student_id | course_id | date_of_registration | |---|---|---|---| | 1 | S101 | CS101 | 17-10-2024 | | 2 | S103 | CS101 | 10-10-2024 | | 3 | S101 | CS201 | 16-10-2024 | | 4 | S102 | CS101 | 17-10-2024 | | 5 | S104 | CS201 | 06-10-2024 | ``` course_id="CS101" ```

```python
count = db.session.query(CourseRegistrations) \
.filter(course_id == "CS101") \
.count()
```
```python
count = db.session.query \
.filter(CourseRegistrations.course_id == "CS101") \
.count()
```
```python
count = db.query(CourseRegistrations) \
.filter(course_id == "CS101") \
.count()
```
```python
count = db.session.query(CourseRegistrations) \
.filter(CourseRegistrations.course_id == "CS101") \
.count()
```
Read the following statements about “index.html” and choose the correct option. Statement 1: Internal element selector blue will be overridden by ID selector red. Statement 2: Internal ID selector red will be overridden by inline styling green.File name: index. html
```html
<!DOCTYPE html>
<html lang="en">
<style>
p{
color: blue;
}
#mypara{
color: red;
}
</style>
<body>
<p id="mypara" style="color: green">IIT BS Degree</p>
</body>
</html>
```
```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)
```
What is the output after the following Python code is executed ? (Assume all entries are successfully committed to the database)
```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='pqrst@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))
```
Choose the correct Python code that will print the output: ['90', '76', '81']?File name: marks.csv | id | name | course1 | course2 | course3 | |---|---|---|---|---| | 1 | Ram Kumar | 90 | 56 | 78 | | 2 | David John | 67 | 76 | 71 | | 3 | Sanju | 56 | 61 | 81 |

```python
import csv
with open("marks.csv") as marks:
rows = csv.reader(marks)
next(rows)
max_m = [max(r[2:]) for r in rows]
print(max_m)
```
```python
import csv
with open("marks.csv") as marks:
rows = csv.reader(marks)
max_m = [max(r) for r in rows]
print(max_m)
```
```python
import csv
with open("marks.csv") as marks:
rows = csv.reader(marks)
next(rows)
max_m = [max(r[2:]) for r in rows]
print(max_m)
```
```python
import csv
with open("marks.csv") as marks:
rows = csv.reader(marks)
max_m = [max(r) for r in rows]
print(max_m)
```
Which of the following statements correctly describes how the elements will be displayed by default in a browser?```html <div> <h1>Content 1</h1> <p>Content 2</p> <span>Content 3</span> <span>Content 4</span> </div> ```
,
and
tags will start on new lines as they are block elements.`<h1/>` `<p>` ```html <span> ```
and
tags will start on new lines, others will display inline.`<h1/>` `<p>`
tags will start on new lines, others will display inline.```html <span> ```
default type is “submit”.```html <button> ```

```html <input type='hidden'> ```
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.
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)
```
```
curl -X POST http://127.0.0.1:5000 -H "Content-Type: application/json" -d '{}'
```
Assume that the Flask app is running at
. What will be rendered for the URL request
?File name: base.html
```html
<!DOCTYPE html>
<html lang="en">
<body>
{% block content %}
<div>Parent content</div>
{% endblock %}
</body>
</html>
```
File name: child.html
```html
{% extends "base.html" %}
{% block content %}
<div>Child content</div>
{% endblock %}
```
File name: app.py
```python
from flask import Flask, render_template
app = Flask(__name__)
@app.route("/home")
def index():
return render_template("child.html")
app.run(debug=True)
```
http://127.0.0.1:5000
http://127.0.0.1:5000/home
File name: app.py
```python
class User(db.Model):
__tablename__ = "user"
id = db.Column(db.Integer, primary_key=True)
full_name = db.Column(db.String, unique=True)
class UserPosts(db.Model):
__tablename__ = "user_posts"
id = db.Column(db.Integer, primary_key=True)
title = db.Column(db.String, unique=True, nullable=False)
description = db.Column(db.String, nullable=True)
user_id = db.Column(db.Integer, db.ForeignKey("user.id"))
class UserApi(Resource):
def post(self):
user_data = request.json
==Missing code 1==
db.session.add(user)
db.session.commit()
return {"msg": "User added!"}, 201
class UserPostsApi(Resource):
def post(self):
post_data = request.json
==Missing code 2==
db.session.add(user_post)
db.session.commit()
return {"msg": "Post added!"}, 201
```
Which of the following is the most suitable ==Missing code 1== and ==Missing code 2==? So that the Flask application does not return any run-time error?
==Missing code 1==
```python
user = User(full_name=user_data["full_name"])
```
==Missing code 2==
```python
user_post = UserPosts(
title=post_data["title"],
description=post_data["description"],
user_id=post_data["user_id"],
)
```
```python
==Missing code 1==
user = User(name=user_data["full_name"])
==Missing code 2==
user_post = UserPosts(
post_title=post_data["title"],
post_description=post_data["description"],
post_user_id=post_data["user_id"],
)
```
```python
==Missing code 1==
user_data = User(full_name=user_data["full_name"])
==Missing code 2==
user_post_data = UserPosts(
title=post_data["title"],
description=post_data["description"],
user_id=post_data["user_id"],
)
```
```
==Missing code 1==
user_data = User(name=user_data["full_name"])
==Missing code 2==
user_post_data = UserPosts(
post_title=post_data["title"],
post_description=post_data["description"],
post_user_id=post_data["user_id"],
)
```
The above code allows courses to be added dynamically to the
element when the user clicks the “Add” Button. What is the most suitable
given below?File name: courses.html
```html
<!DOCTYPE html>
<html lang="en">
<body>
<label>Enter course :</label>
<input type="text" id="txt_course">
<button onclick="add_item()">Add</button><br>
Courses:<br>
<ul id="courses">
<!-- Empty courses-->
</ul>
<script>
function add_item(){
course=document.getElementById("txt_course").value;
document.getElementById("txt_course").value="";
// Missing JS Code snippet
}
</script>
</body>
</html>
```
Expected output:
Enter course : [text input field] [Add button]
Courses:
* Java
* PDSA
```html
<ul>
```
```javascript
//Missing JS Code snippet
```
```javascript
courses=document.getElementById("txt_course");
courses.innerHTML=courses.innerHTML+"<li>"+course+"</li>";
```
```javascript
courses=document.getElementById("courses");
courses.innerHTML=courses.innerHTML+"<li>"+course+"</li>";
```
```javascript courses.innerHTML=courses.innerHTML + "<li>"+course+"</li>"; ```

```javascript courses.innerHTML = "<li>"+course+"</li>"; ```
What will be the output when the above HTML file is rendered?```html
<!DOCTYPE html>
<html>
<head>
<style>
p { color: blue; }
.text { color: green; }
#para { color: red; }
</style>
</head>
<body>
<p id="para" class="text" style="color: black;">
IITM BS Degree Program
</p>
</body>
</html>
```
IITM BS Degree Program

IITM BS Degree Program

IITM BS Degree Program

IITM BS Degree Program

```python
@app.route("/user/id")
```
```python
@app.route("/user/<int:id>")
```
```python
@app.route("/user/<id>")
```
```python
@app.route("/user/<float:id>")
```

```python
from flask import Flask
app=Flask(__name__)
@app.route("/user/<name>")
def greet(name):
return f"<p>Welcome {name}</p>"
app.run(debug=True)
```
Assume that the Flask app is running at http://127.0.0.1:5000. Which of the following URL requests will render the output without any errors?

Filename: app.py
```python
from flask import Flask, render_template
app=Flask(__name__)
@app.route("/")
def home():
return render_template("index.html")
app.run(debug=True)
```
Filename: index.html
```html
<!DOCTYPE html>
<html lang="en">
<body>
<div>
Output is:
{% for i in [1,2,3] %}
{% set x = i %}
{% endfor %}
{{ x }}
</div>
</body>
</html>
```
Assume that the Flask app is running at http://127.0.0.1:5000. What will be the rendered output
in the browser for the URL: http://127.0.0.1:5000?
What will be the output in the console window when the above HTML doc is rendered on the browser ?```html
<!DOCTYPE html>
<html>
<body>
<ol id="lst">
<li>App Dev-1</li>
</ol>
</body>
<script>
let lst_items=document.getElementsByTagName("li");
document.getElementById("lst").innerHTML += "<li>App Dev-2</li><li>App dev projects</li>";
console.log(lst_items.length);
</script>
</html>
```

```python
from flask import Flask
from flask_restful import Resource, Api
app = Flask(__name__)
api = Api(app)
products = [
{"id": 1, "name": "books", "price": 56},
{"id": 2, "name": "pens", "price": 61},
{"id": 3, "name": "bulbs", "price": 76},
]
class MyApiResource(Resource):
### Missing code ###
api.add_resource(MyApiResource, "/<int:id>")
if __name__ == "__main__":
app.run(debug=True)
```
Assume that the Flask app is running at http://127.0.0.1:5000. Which of the following codes when placed at ###Missing code ### will work correctly to search a product by id?
```python
def post(self):
for p in products:
if p["id"] == id:
return f"{p['id']}, {p['name']}, {p['price']}"
return f"msg: {id} not found"
```
```python
def get(self,id):
for p in products:
if p["id"] == id:
return f"{p['id']}}, {p['name']}}, {p['price']}}"
return f"msg: {id} not found"
```
```python
def get(self):
for p in products:
if p["id"] == id:
return f"{p['id']}, {p['name']}, {p['price']}"
return f"msg: {id} not found"
```
```python
def post(self, id):
for p in products:
if p["id"] == id:
return f"{p['id']}, {p['name']}, {p['price']}"
return f"msg: {id} not found"
```
Based on the above data, answer the given subquestions.
```python >>> u1 = User(uname = "Jane", pwd = "1234") >>> p1 = Profile(name = "Analyst", email = "zoozle.com", user_id = u1.id) >>> db.session.add_all([u1,p1]) >>> db.session.commit() >>> user1 = User.query.filter_by(uname="Jane").first() >>> user1.profile ```

<User 1>

``` [<Profile 1>] ```

```html <Profile 1> ```

``` 'Analyst' ```
Which of the following will be the rendered output?```html
<!DOCTYPE html>
<html>
<head>
<style>
p {
background-color: yellow;
display:inline-block;
}
div p {
background-color: lightblue;
}
.highlight {
background-color: pink;
}
#special {
background-color: orange;
}
</style>
</head>
<body>
<div>
<p class="highlight">Paragraph One</p>
<p class="highlight" id="special">Paragraph Two</p>
<p>Paragraph Three</p>
</div>
</body>
</html>
```
Paragraph One Paragraph Two Paragraph Three

Paragraph One Paragraph Two Paragraph Three

Paragraph One Paragraph Two Paragraph Three

Paragraph One Paragraph Two Paragraph Three

File name: home.html
```html
<body>
{% if user == "admin" %}
<p>Welcome Admin</p>
{% else %}
<p>Welcome User</p>
{% endif %}
</body>
```
File name: app.py
```python
from flask import Flask,render_template
app = Flask(__name__)
@app.route("/")
def login():
return render_template("home.html",user="admin iitm")
app.run(debug=True)
```
Assume that the above code is running on http://127.0.0.1:5000. What will be the rendered output for the URL request http://127.0.0.1:5000 ?
What will be the output in the terminal?```python
from jinja2 import Template
temp = """
{% set numbers = [5, 2, 8, 1, 9] %}
{% for num in numbers|sort -%}
<p>{{ num }}</p>
{%- endfor %}
"""
made_temp = Template(temp)
result = made_temp.render()
print(result)
```
```html <p>5</p><p>2</p><p>8</p><p>1</p><p>9</p> ```

```html <p>1</p><p>2</p><p>5</p><p>8</p><p>9</p> ```

```html <p>9</p><p>8</p><p>5</p><p>2</p><p>1</p> ```

```html <p>12589</p> ```

Template will throw an error

Consider the following Flask application running on http://127.0.0.1:5000.
```python
from flask import Flask
app = Flask(__name__)
@app.route('/profile/<string:username>')
def profile(username):
return f"Profile of {username}"
@app.route('/post/<int:post_id>')
def post(post_id):
return f"Post ID: {post_id}"
app.run(debug=True)
```
What will happen when accessing http://127.0.0.1:5000/post/abc123 ?
```python
users = [[{ "id":1, "name": "user_1", "role": "manager"},
{ "id":2, "name": "user_2", "role": "manager"},
{ "id":3, "name": "user_3", "role": "manager"}]]
```
An ordered HTML list is to be created for users where every list item should have a clickable "name" attribute redirecting to the endpoint "/show_users/<id>" where "id" is the "id" attribute of the same user dictionary. Which of the following is the correct way of doing it with jinja and HTML?
```html
<ol>
{% for user in users %}
<li><a href="/show_users/{{user.id}}">{{user.name}}</a></li>
{% endfor %}
</ol>
```
```html
<ol>
{% for user in users %}
<li><a href="/show_users/{{user['id']}}">{{user['name']}}</a></li>
{% endfor %}
</ol>
```
```html
<ol>
<li><a href="/show_users/{{users[0].id}}">{{users[0].name}}</a></li>
<li><a href="/show_users/{{users[1].id}}">{{users[1].name}}</a></li>
<li><a href="/show_users/{{users[2].id}}">{{users[2].name}}</a></li>
</ol>
```
```html
<ol>
{% for user in users %}
<li><a href="/show_users/{{user.name[-1]}}">{{user.name}}</a></li>
{% endfor %}
</ol>
```
Which of the following statements are TRUE regarding the element's dimensions and spacing?```css
#container {
width: 200px;
padding: 10px;
border: 2px solid black;
margin: 15px;
}
```
If the flask app is running locally on http://127.0.0.1:5000. What will be the output on the browser for the base URL?app.py
```python
from flask import Flask, render_template
app = Flask(__name__)
@app.route('/')
def home():
return render_template("index.html", items=['DaShBoard', 'SETtings',
'HELP'])
app.run()
```
index.html
```html
<!DOCTYPE html>
<html lang="en">
<head>
<title>Menu</title>
</head>
<body>
{% macro nav_list(elements) %}
<ol>
{% for element in elements %}
<li><a href="/{{ element|lower }}">{{ element|upper }}</a></li>
{% endfor %}
</ol>
{% endmacro %}
{{ nav_list(items) }}
</body>
</html>
```
1. DaSHBoard 2. SETtings 3. HELP

1. dashboard 2. settings 3. help

1. DASHBOARD 2. SETTINGS 3. HELP

1. DASHBOARD 2. SETTINGS 3. HELP
Which of the following flask_sqlalchemy models will create exactly the same table as created by the above SQL command?```sql
CREATE TABLE employee (
emp_id INTEGER NOT NULL,
emp_code VARCHAR() NOT NULL,
name VARCHAR(),
salary INTEGER NOT NULL,
join_date DATE NOT NULL,
PRIMARY KEY (emp_id),
UNIQUE (emp_code),
UNIQUE (name)
)
```
```python
class Employee(db.Model):
emp_id = db.Column(db.Integer(), unique=True)
emp_code = db.Column(db.String(), primary_key=True)
name = db.Column(db.String(), unique=False)
salary = db.Column(db.Integer())
join_date = db.Column(db.Date())
```
```python
class Employee(db.Model):
emp_id = db.Column(db.Integer(), primary_key=True)
emp_code = db.Column(db.String(), nullable=False, unique=True)
name = db.Column(db.String(), unique=True)
salary = db.Column(db.Integer(), nullable=False)
join_date = db.Column(db.Date(), nullable=False)
```
```python
class Employee(db.Model):
emp_id = db.Column(db.Integer(), primary_key=True)
emp_code = db.Column(db.String(), unique=True)
name = db.Column(db.String(), unique=True, nullable=False)
salary = db.Column(db.Integer())
join_date = db.Column(db.Date())
```
```python
class Employee(db.Model):
emp_id = db.Column(db.Integer(), nullable=False)
emp_code = db.Column(db.String(), unique=True)
name = db.Column(db.String())
salary = db.Column(db.Integer(), nullable=False)
join_date = db.Column(db.Date(), nullable=False)
```
Based on the above data, answer the given subquestions.


Given the following test code:
```python
def test_about(client):
response = client.get('/about')
assert response.status_code == 200
assert b'This is the about page.' in response.data
```
Assume the client fixture works correctly and you are testing a Flask route `/about` that should return the text "This is the about page.". Which of the following options would cause this test to fail?
The route `/about` is missing in `app.py`.

The route `/about` exists but returns "About us page" instead.

The route `/about` returns `<p>this is the about page.</p>` instead of plain text.
The Requests table represents service bookings made by customers. Based on the above data, answer the given subquestions.


```sql SELECT c.name, s.service_name FROM customers c, services s WHERE c.id = s.id; ```

```sql SELECT c.name, r.status FROM customers c JOIN services s ON c.id = s.id; ```

```sql SELECT c.name, s.service_name FROM customers c JOIN requests r ON c.id = r.customer_id JOIN services s ON r.service_id = s.id; ```

```sql SELECT c.name, s.service_name FROM services s LEFT JOIN customers c ON s.id = c.id; ```
The Requests table represents service bookings made by customers. Based on the above data, answer the given subquestions.


```sql SELECT r.customer_id, COUNT(*) AS total_requests FROM requests r; ```

```sql SELECT c.name, COUNT(r.service_id) AS total_requests FROM customers c JOIN requests r ON c.id = r.customer_id GROUP BY c.name; ```

```sql SELECT c.name, COUNT(s.id) AS total_requests FROM customers c JOIN services s ON c.id = s.id GROUP BY c.name; ```

```sql SELECT c.name, r.service_id FROM customers c JOIN requests r ON c.id = r.customer_id; ```
The Requests table represents service bookings made by customers. Based on the above data, answer the given subquestions.


```python customer = Customer.query.filter_by(id=1).first() services = Service.query.all() ```

```python services = Service.query.filter_by(customer_id=1).all() ```

```python customer = Customer.query.get(1) services = [r.service for r in customer.requests] ```

```python services = Request.query.filter_by(id=1).all() ```

```javascript
document.getElementById("myBtn").onclick = function() {alert("Clicked!");
};
```
```javascript
document.getElementById("myBtn").addEventListener("click", function() {
alert("Clicked!");
});
```
```html
<button onclick="alert('Clicked!')">Click Me</button>
```
What will be the output of the following code?
```html
<script>
function greet(name = "Guest") {
return "Hello, " + name;
}
console.log(greet());
console.log(greet("Alice"));
</script>
```
Hello, Guest Hello, Alice

``` Hello, undefined Hello, Alice ```

``` Hello, Guest '[object console]' ```

You want to change the text of a `<p>` element with `id="msg"` to "Welcome to JavaScript!" when a button is clicked. Which code snippet correctly does this?
```html
<p id="msg">Old Message</p>
<button id="btn">Change</button>
<script>
// Code goes here
</script>
```
```javascript
document.getElementById("btn").onclick = function() {
document.getElementById("msg").innerHTML = "Welcome to JavaScript!";
};
```
```javascript
document.getElementById("btn").addEventListener("click", function() {
msg.text = "Welcome to JavaScript!";
});
```
```javascript
document.querySelector("#btn").addEventListener("click", function() {
document.querySelector("#msg").innerText = "Welcome to JavaScript!";
});
```
```javascript
document.getElementById("btn").onclick = function() {
document.getElementById("msg").innerHTML = "Welcome to JavaScript!";
};
```
Consider the following HTML5 form:
```html
<form method="POST" action="/submit">
<input type="email" name="email" required>
<input type="password" name="password" required minlength="8">
<input type="number" name="age" min="18" max="65" required>
<button type="submit">Submit</button>
</form>
```
Which of the following attributes are HTML5 native validation features that work without JavaScript?
Consider the following Flask-RESTful code:
```python
class UserResource(Resource):
def get(self, user_id=None):
if user_id:
return {"message": "User details", "id": user_id}, 200
return {"message": "All users"}, 200
def post(self):
return {"message": "User created"}, 201
api.add_resource(UserResource, '/users', '/users/<int:user_id>')
```
Which of the following requests will execute successfully?
```
{{ courses | len }}
```
```jinja
{{ courses | length }}
```
```html
{{ len(courses) }}
```
None of these

Consider the following statements and select the correct option. Statement 1: The `<span>` elements will start on new lines, while the `<div>` elements will appear inline with surrounding content. Statement 2: The `<p>` and `<div>` elements will each start on new lines and take up the full width of their container, while `<span>`, `<strong>`, and `<em>` will flow inline with surrounding content.

Match the following web development concepts with their correct descriptions: | Column A | Column B | |---|---| | 1. PyHTML | A. Lightweight engine in Python for embedding variables inside strings using `$variable` style | | 2. Jinja2 | B. A Python library to build HTML structures programmatically using Python functions | | 3. Template Rendering | C. The process of generating dynamic HTML by combining templates with data | | 4. String Template Rendering | D. Templating engine used by Flask that supports control structures, filters, and inheritance |

Consider the following HTML and CSS code:
```html
<html>
<head>
<style>
div {
width: 0px;
margin: 0px;
}
.container {
width: 200px;
padding: 15px;
border: 5px solid black;
}
#box {
margin: 10px;
}
</style>
</head>
<body>
<div class="container" id="box">Hello World</div>
</body>
</html>
```
What is the **total width (approximately)** of the `div` with `class="container"` and `id="box"`, including **content, padding, and border** but excluding margin?
Consider the following code:
```python
from flask import Flask, request, render_template_string
app = Flask(__name__)
@app.route('/', methods=['GET', 'POST'])
def home():
if request.method == 'POST':
name = request.form['name']
template = "Hello, {{ name }}!"
return render_template_string(template, name=name)
return '''
<form method="POST">
Enter Your Name: <input type="text" name="name">
<button>Submit</button>
</form>
'''
if __name__ == '__main__':
app.run(debug=True)
```
You are building a Flask web application that takes user input from an HTML form and displays it using Jinja2 templates. Suppose the user runs this app locally and submits the name **Alice** in the form.
Which of the following represents the correct sequence of concepts that occur when the user submits the form with the name **Alice** ?
HTML Form Rendering → HTTP 404 Not Found Error → User Submits Form → Flask Routing → Template Rendering

User Submits Form (HTTP POST) → Check URL Structure → Network Transfer (Bandwidth & Latency) → Flask Routing

User Accesses URL (Form at "/") → User Submits Form (HTTP POST) → Flask Request Handling (request.form) → Jinja2 Template Rendering

Flask Request Handling → Network Round Trip (RTT) → HTML Table Rendering → Jinja2 Template Rendering