Home / Past papers / MAD1 End Term / this paper
Consider the URL given below. http://appdev1.com/sep-22?week=2#MVC Which of the following options correctly describes each component of the URL given above? | URL Component | Name | | :------------ | :------------ | | 1. http | A. Domain Name | | 2. appdev1.com | B. Query String | | 3. /sep-22 | C. Protocol | | 4. ?week=2 | D. Fragment | | 5. #MVC | E. Path |
Consider the following flask python snippet with all preliminary conditions. ```python
class User(UserMixin, db.Model):
id = db.Column(db.Integer, primary_key = True)
name = db.Column(db.String(30))
def __init__(self, id, name):
self.id = id
self.name = name
@login_manager.user_loader
def firstuser(id):
return User.query.get(int(id))
@app.route('/')
def index():
u1 = User.query.filter_by(id = 112).first()
login_user(u1)
return current_user.name + ' logged in'
@app.route('/logout')
@login_required
def logout():
logout_user()
return 'logged out'
@app.route('/home')
@login_required
def home():
return "current user is " + current_user.name
def init_db():
db.create_all()
new_user = User(112, 'Rose')
new_user2 = User(113, 'lily')
db.session.add(new_user)
db.session.add(new_user2)
db.session.commit()
if __name__ == '__main__':
init_db()
app.run(debug = True)
```
If the above program is running in the URL “http://127.0.0.1:8000” then what will be the output for the given URLs in sequence.
* http://127.0.0.1:8000
* http://127.0.0.1:8000/home
* http://127.0.0.1:8000/logout
```html
<ul>
{% for item in navigation %}
<li>
<a href="{{item.href}}">{{item.title}}</a>
</li>
{% endfor-navigation %}
</ul>
```
```html
<ul>
{{ for item in navigation }}
<li>
<a href = "{%item.href%}">{%item.title%}</a>
</li>
{{ endfor }}
</ul>
```
```html
<ul>
{% for item in navigation %}
<li>
<a href="{{item.href}}">{{item.title}}</a>
</li>
{% endfor %}
</ul>
```
```html
<ul>
{% for item in navigation %}
<li>
<a href="{{item.href}}">{{item.title}}</a>
</li>
{% end %}
</ul>
```
A template named userinfo.html contains the following line inside the body tag: ```html
<h1> Hello {{user_name}}! </h1>
```
Which of the following code snippets will utilize the template to display **Hello Ram** when **http://localhost:5000/user/Ram** is visited on the browser?
```python
@app.route('/user/<name>')
def user():
return render_template('userinfo.html',user_name=name)
```
```python
@app.route('/user/<name>')
def user(name):
return render_template('userinfo.html',user_name=name)
```
```python
@app.route('/user/<user_name>')
def user(name):
return render_template('userinfo.html', user_name = name)
```
```python
@app.route('/user/<name>')
def user(name):
return render_template('templates/userinfo',user_name=name)
```
Given the resource below, What is displayed when a user visits “http://localhost:5000/hello” on the browser? ```python
from flask_restful import Api
api = Api(app)
class Hello(Resource):
def post(self):
return {'User':'Abhishek'}
api.add_resource(Hello, '/hello')
```
HTTP 404 - Page Not Found Error

```json
{
"Hello": "Abhishek"
}
```
Hello Abhishek

```json
{
"message": "The method is not allowed for the requested URL."
}
```
A server, using the inbuilt http module of Python, is running for a directory My_app whose file structure and content of each file is given below. Folder: My_app My_app |__home.html |__index.html |__main.html File: home.html ```html <h1>Hello from Home!</h1> ``` File: index.html ```html <h1>Hello from Index!</h1> ``` File: main.html ```html <h1>Hello from Main!</h1> ``` What will be rendered by the browser for the URL: http://localhost:8000 assuming that 8000 is the port of connection?

Directory listing for / * home.html * index.html * main.html

Hello from Home!

Hello from Index!

Hello from Main!
Match the following: Which of the following is the correct?| | | |---|---| | A. API | 1. Servers do not assume anything about the client's state; they only serve responses. | | B. MVC | 2. An action is assigned to each uniform resource locator. | | C. Routing | 3. A standard way defined between two applications for them to communicate. | | D. Stateless | 4. A design pattern that emphasizes the separation of concerns. |
Consider the following HTML page with javascript, which is running at the URL http://127.0.0.1:8000, then choose the correct HTML rendering. ```html
<!DOCTYPE html>
<html>
<body>
<h2>Creating a JSON String</h2>
<p id="demo"></p>
<script>
const txt = '{"name":"Balu", "age":30, "city":"New Delhi"}'
const obj = JSON.parse(txt);
document.getElementById("demo").innerHTML = "Hi\n" + obj.name + ",\t" + obj.city + "," + obj.age*3;
</script>
</body>
</html>
```
Creating a JSON String Hi Balu, New Delhi,30

Creating a JSON String Hi Balu, 30, New Delhi

Creating a JSON String Hi Balu, New Delhi,90

Creating a JSON String Hi Balu, 90, New Delhi
If the given python program is executed using pytest, then identify the status of the test code. File name: test1.py ```python
def dec(x):
return x-1
def test_answer():
assert dec(3) == 3
```
```python
@app.route('/')
def index():
return render_template('index')
```
```python
@app.route('/')
def index():
return render_template('index.html')
```
```python
@app.route('/')
def index():
return render_template(index.html)
```
```python
@app.route('index.html')
def index():
return render_template('/')
```
In the given HTML template, to correctly embed a URL in the href, the argument "user" in the "url_for" function must be a __________________? ```html
<a href = {{ url_for('user')}}>Click here</a>
```
Consider the following constraints for the “student” table: | Column Name | Datatype | Constraints | |---|---|---| | RollNo | Integer | Primary Key | | Name | String | Not Null | | AadhaarNo | Integer | Not Null, UNIQUE | | Department | String | Not Null | In most cases, the query executed in the student table looks like the one below. ```sql SELECT RollNo, Name, AadhaarNo FROM student WHERE Department = 'Biology'; ``` For the above student table, which of the following columns would be the most appropriate for the indexing?

Git is an example of a centralized version control system.

A file can stay in both working directory and staging area at a given time, while working with Git.

Git and GitLab/GitHub are essentially the same.

The command "git checkout -b <branch_name>" will create the new branch and switches to the new branch created.
Consider the following Model for User. ```python
class User(db.Model):
id = db.Column(db.Integer, primary_key=True)
email = db.Column(db.String(100), unique=True, index=True)
name = db.Column(db.String(100))
password = db.Column(db.String(100))
```
Which of the following methods from the Flask-sqlalchemy package will behave the same as SQL query `select * from User where name='Ram'`?
```python User.query.filter(User.name = 'Ram').all() ```

```python User.query.get(name = 'Ram').all() ```

```python
User.query.filter_by('Ram').all()
```
```python User.query.filter_by(name = 'Ram').all() ```
Consider the following Python code snippet: Filename: module_0.py
```python
import sys
arguments = sys.argv
courses = {'MAD-1': '1002', 'MAD 2': '2003', 'BDM': '205', 'SysCom': '304'}
def operate():
arg_1 = arguments[1]
arg_2 = courses[arg_1]
return f"The function output is: {len(arg_1 + arg_2)}"
print(operate())
```
The above file will yield the output as "The function output is: 9", for which of the following command line inputs?
``` python module_0.py MAD-1 ```

``` python module_0.py MAD 2 ```

``` python module_0.py BDM ```

``` python module_0.py SysCom ```

Consider two software packages A and B spend exactly $T_A(N) = 2N^2 + 9$ and $T_B(N) = N^3$ milliseconds to process N data items. Analyze the software packages and select the correct statement(s).
Consider the following Python code snippet. ```python
from flask import Flask, abort, redirect, url_for, render_template
app = Flask(__name__)
data_science = ['ML-techniques', 'ML-foundations', 'ML-practices']
programming = ['Java', 'MAD-I', 'System-Commands', 'PDSA']
@app.route('/courses/<course>')
def find_course(course):
if course in data_science:
return f"<h2>Data Science course found, {course}!</h2>"
elif course in programming:
return f"<h2>Programming course found, {course}!</h2>"
else:
abort(401)
@app.errorhandler(401)
def page_not_found(error):
return "<h2>No course found!</h2>"
app.run()
```
If the above application is running locally on URL: http://127.0.0.1:5000, select the correct statement(s).
For the URL, "http://localhost:5000/courses/ML-techniques", the browser will render: **Programming course found, ML-techniques!**

For the URL, "http://localhost:5000/courses/ML-practices", the browser will render: **Data Science course found, ML-practices!**

For the URL, "http://localhost:5000/courses/MAD-2", the browser will render: **No course found!**

For the URL, "http://localhost:5000/courses/Java", the browser will render: **Data Science course found, Java!**
Consider the following two tables, user1 and logstable: user1: | userid | name | password | | :----- | :---- | :------- | | U1 | Mack | UabZa | | U2 | Jack | ZeFad | | U3 | Shaun | UsTZb | logstable: | logid | userid | name | | :---- | :----- | :-------- | | 1 | U1 | Playing | | 2 | U2 | Studying | | 3 | U3 | Swimming | | 4 | U1 | Running | | 5 | U3 | Studying | | 6 | U2 | Dancing | Which of the following query/queries will return the log ID and log name, which are created by user 'Shaun'?

```sql select logid, logstable.name from user1 inner join logstable on user1.userid = logstable.userid where user1.name = 'Shaun' ```

```sql select logid, logstable.name from user1 natural join logstable where user1.name = 'Shaun' ```

```sql select logid, logstable.name from user1 inner join logstable on user1.name = logstable.name where user1.name = 'Shaun' ```

```sql select logid, logstable.name from user1, logstable WHERE user1.userid = logstable.userid and user1.name = 'Shaun' ```
Consider the following jinja2 template, and answer the given subquestions
What will be the output on the terminal for: ```python
data = {'a': 'programming', 'b': 'mathematics', 'c': 'statistics',
'd': 'machine learning'}
```
Data science combines programming abilities and competence in mathematics and statistics to draw important insights from data.

Data science combines programming abilities and competence in mathematics and machine learning to draw important insights from data.

machine learning combines programming abilities and competence in mathematics and statistics to draw important insights from data.

KeyError: 'd'
What will be the output on the terminal for: ```python
data = {'b': 'mathematics', 'c': 'statistics', 'd': 'programming'}
```
Data science combines {{a}} abilities and competence in
mathematics and statistics to draw important insights from data.
Data science combines abilities and competence in mathematics and statistics to draw important insights from data.

Data science combines programming abilities and competence in mathematics and statistics to draw important insights from data.

KeyError: 'a'
Consider the below model definitions, and answer the given subquestions. Consider the following model classes “Movies” and “Producers” corresponding to tables “movies” and “producers”, respectively, in the SQLite database. 
If an object "p1" that represents an existing record in the table "producer" is defined as ``` p1 = Producer.query.get(2), ``` The correct way to create a new record in the "movies" table that is produced by the producer represented by object 'p1' using terminal is.

```python >>> mov = Movies(movie_name = 'The movie', movie_year = 2001, producers = p1) >>> db.session.add(mov) >>> db.session.commit() ```

```python >>> mov = Movies(movie_name = 'The movie', movie_year = 2001) >>> p1.producers.append(mov) >>> db.session.commit() ```

```python >>> mov = Movies(movie_name = 'The movie', movie_year = 2001) >>> p1.movie.append(mov) >>> db.session.commit() ```

```python mov = Movies(movie_name = 'The movie', movie_year = 2001) mov.producers.append(p1) db.session.commit() ```
Consider the below program, and answer the given subquestions , if the application is running locally on URL: http://127.0.0.1:5000. Consider the following resource created with help of flask-restful.
If the curl request shown below. ```
curl http://127.0.0.1:5000/api/v1 -X GET -d "{\"employee_id\": \"2003\", \"employee_name\": \"Suresh\"}" -H "Content-Type: application/json"
```
retrieves the employee_id only with status 200 OK, what will come in place of GET-FUNCTION in the code?
```python
def get(self):
return {'employee_Id': employee_id}
```
```python
def get(self, employee_id):
return {'employee_id': employee_id}
```
```python
def get(self):
args = parser.parse_args()
return {'Id_no.': args['employee_id']}
```
```python
def get(self):
args = parser.parse_args()
return args
```
If the curl request shown below ``` curl http://127.0.0.1:5000/api/v1/5001 -X POST retrieves the employee_id only with status 200 OK, what will come in place of POST-FUNCTION in the code? ```

```python
def post(self):
return {'employee_Id': employee_id}
```
```python
def post(self, employee_id):
return {'employee_id': employee_id}
```
```python
def post(self):
args = parser.parse_args()
return {'id_no.': args['employee_id']}
```
```python
def post(self):
args = parser.parse_args()
return args
```
What will be the response from the server for the request: ```
curl http://127.0.0.1:5000/api/v1 -X PUT -d "{\"employee_id\": \"2003\", \"employee_name\": \"Suresh\"}" -H "Content-Type: application/json"
```
```json
{
"employee_id": "2003",
"employee_name": "Suresh"
}
```
```json
{
"employee_id": "2003"
}
```
```json
{
"employee_name": "Suresh"
}
```
None of these
Consider the below graph, and answer the given subquestions. The bandwidth vs. time graph for a period of one hour between 12 noon to 1 p.m in the afternoon is shown below. [Use relations: 1 Byte = 8 bits, 1 GB = 1000 MB and so on.] Auto-generated summary from the source site. Handy as a checklist; the lessons above explain each idea from scratch.
Here’s a structured summary of core topics, concepts, principles, and equations essential for the "Diploma Level: Modern Application Development 1" exam, followed by Mermaid knowledge graphs to visualize relationships.
URL Structure
Protocol (e.g., http), Domain (e.g., appdev1.com), Path (e.g., /sep-22), Query String (e.g., ?week=2), Fragment (e.g., #MVC).Equation/Example:
http://appdev1.com/sep-22?week=2#MVC
Protocol: http
Domain: appdev1.com
Path: /sep-22
Query: ?week=2
Fragment: #MVCHTTP Methods & Status Codes
GET, POST, PUT, DELETE.200 OK, 401 Unauthorized, 404 Not Found, 500 Server Error.Example:
@app.route('/logout')
@login_required
def logout():
logout_user()
return 'logged out' # HTTP 200Flask Framework
@app.route('/path').Templates: Jinja2 syntax ({% %}, {{ }}).
Example (For Loop):
{% for item in navigation %}
<li><a href="{{ item.href }}">{{ item.title }}</a></li>
{% endfor %}Example (Template Inheritance):
{% extends 'base.html' %}Forms & User Authentication:
flask_login (e.g., login_user, logout_user, @login_required).Example:
@login_manager.user_loader
def load_user(user_id):
return User.query.get(int(user_id))Flask-RESTful:
reqparse, marshal_with.Example:
parser = reqparse.RequestParser()
parser.add_argument('employee_id')HTML/CSS
Inline vs. Internal vs. External Styles:
Inline > Internal > External.Example:
<p style="color: red;">Inline CSS</p> <!-- Highest precedence -->Jinja2 Templating
{{ variable }}.Conditionals/Loops:
{% if user %} Hello {{ user }}! {% endif %}{% extends 'base.html' %}.SQL Queries
SELECT, WHERE, JOIN (INNER, NATURAL), GROUP BY.Example (JOIN):
SELECT logid, logstable.name
FROM user1
INNER JOIN logstable ON user1.userid = logstable.userid
WHERE user1.name = 'Shaun';Example (Filtering):
User.query.filter_by(name='Ram').all() # Equivalent to SQL WHERESQLAlchemy (ORM)
Model Definition:
class User(db.Model):
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(30))Relationships:
secondary table).Example (Many-to-Many):
producers = db.relationship('Producer', secondary='groups')Indexing
Department in WHERE clauses).Example:
CREATE INDEX idx_department ON student(Department);Key Concepts
Branching:
git checkout -b new_branch # Creates and switches to `new_branch`Commands
git add, git commit, git push, git checkout.Continuous Integration (CI) & Delivery (CD)
Testing
Unit Testing with pytest:
Example:
def test_answer():
assert dec(3) == 2 # Fails if dec(3) returns 3Output for failure:
assert 2 == 3Bandwidth Calculation
1 Byte = 8 bits, 1 GB = 1000 MB.Example:
If bandwidth is 7 Mbps for 30 minutes (1800 seconds):
Total data = 7 Mbps * 1800 s = 12600 Mbits = 1.575 GBTime Complexity
O(N²) vs. O(N) for small inputs (e.g., N ∈ [0, 3]).Example:
T_A(N) = 2N² + 9 vs. T_B(N) = N²:
N=3: T_A(3) = 27, T_B(3) = 9 → B is faster.Relationships in SQLAlchemy
Groups for Movies and Producers).Example:
class Groups(db.Model):
movie_id = db.Column(db.Integer, db.ForeignKey('movies.id'), primary_key=True)
prod_id = db.Column(db.Integer, db.ForeignKey('producer.id'), primary_key=True)| Topic | Equation/Code |
|---|---|
| URL Structure | protocol://domain/path?query#fragment |
| Flask Route | @app.route('/path') |
| Jinja2 For Loop | {% for item in list %} {{ item }} {% endfor %} |
| SQL JOIN | SELECT * FROM A INNER JOIN B ON A.id = B.id WHERE A.name = 'X'; |
| SQLAlchemy Filter | User.query.filter_by(name='Ram').all() |
| Git Branch | git checkout -b new_branch |
| Bandwidth to Data | Data (GB) = Bandwidth (Mbps) * Time (s) / (8 * 1000²) |
| Time Complexity | O(N²) vs. O(N) for N ∈ [0, 3] |
| Flask-RESTful Parser | parser.add_argument('field') |
| Pytest Assertion | assert function(input) == expected_output |
JOIN queries and SQLAlchemy relationships.pytest assertions and failure messages.