Home / Past papers / MAD1 Quiz 1 / this paper
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>`
Assume that the Flask app is running at http://127.0.0.1:5000. Based on the above data, answer the given subquestions.
Enter a number : [text input field with "5" entered] [Submit button]
What will be the output when you run the following code in the terminal
and then access in the browser with the following link
?```python
from flask import Flask
import sys
app = Flask(__name__)
MULTIPLIER = int(sys.argv[1]) if len(sys.argv) > 1 else 2
@app.route('/calculate/<int:value>')
def calculate(value):
return f"Result: {value * MULTIPLIER}"
if __name__ == '__main__':
app.run()
```
```
python app.py 7
```
http://localhost:5000/calculate/6
```python
from flask import Flask, request
app = Flask(__name__)
@app.route("/total")
def total():
price = request.args.get("price", 0)
qty = request.args.get("qty", 1)
result = price * qty
return str(result)
app.run()
```
Assume that the above Flask app is running at http://127.0.0.1:5000. What will be rendered for the URL request http://127.0.0.1:5000/total?price=5&qty=2?
File name: app.py
```python
from string import Template
student_record = ["Siya", "Sunita"]
for name in student_record:
template_layout = "Student Name: $name "
template = Template(template_layout)
print(template.substitute(name=name))
```
What text output is generated when this script is executed by the command `python app.py`?
```python
from flask import Flask
app = Flask(__name__)
@app.route("/user/<name>")
def user(name):
return f"User: {name}"
@app.route("/user/admin")
def admin():
return "Admin Panel"
app.run()
```
Assume that the Flask app is running at http://127.0.0.1:5000. What response is returned when http://127.0.0.1:5000/user/admin is accessed?
File name: app.py
```python
from flask import Flask
app = Flask(__name__)
@app.route("/calculate/<int:v1>/<int:v2>")
def compute(v1, v2):
try:
return f"{v1 / v2}"
except:
return "Arithmetic operation error!"
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 return **Not Found** ?
``` http://127.0.0.1:5000/calculate/10/5 ```

``` http://127.0.0.1:5000/calculate/3/0.2 ```

``` http://127.0.0.1:5000/calculate/3/2?v1=1 ```

``` http://127.0.0.1:5000/calculate?v1=5&v2=2 ```

File name: main.py
```python
from jinja2 import Template
import sys
t = """
Better learning path of App Dev courses:
=>{{course[0]}} => {{course[1]}} => {{course[2]}} => {{course[3]}}
"""
course = sys.argv[1:]
render_t = Template(t)
output = render_t.render(course=course)
print(output)
```
Which of the following is the correct command to render the following **output**?
**Output**:
Better learning path of App Dev courses:
=>MAD1 => MAD2 => MAD1_Project => MAD2_Project
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.
Which of the following students is classified as "Pass" by the template?```python
from jinja2 import Template
students = [
{"name": "Alice", "marks": [80, 90]},
{"name": "Bob", "marks": [50, 40]},
{"name": "Kittu", "marks": [51,66]},
{"name": "Carol", "marks": [100]}
]
template = Template("""
{% for student in students %}
{% set avg = (student.marks | sum) / (student.marks | length) %}
{{ student.name }} :
{% if avg > 75 %}
Distinction
{% elif avg > 50 %}
Pass
{% else %}
Fail
{% endif %}
{% endfor %}
""")
print(template.render(students=students))
```Auto-generated summary from the source site. Handy as a checklist; the lessons above explain each idea from scratch.
Here's a summary of the core topics, concepts, principles, and equations essential to study for the exam, followed by a knowledge graph.
The questions cover fundamental aspects of Web Development, specifically focusing on Frontend Technologies (HTML, CSS) and Backend Development with Python Flask, alongside core Python Programming concepts and some Mathematical/Networking Fundamentals.
HTML Structure and Elements:
<!DOCTYPE html>, <html>, <head>, <body>).<div>, <h3>, <input>, <form>, <ul>, <li>.<div>, <p>, <h1>) from those that flow with text and take only necessary width (e.g., <span>, <a>, <img>, <input>).<input type="text">, <input type="submit">.CSS Styling and Selectors:
<style> tag in HTML.CSS Selector Specificity: The mechanism by which browsers decide which CSS rules to apply.
#id) have higher specificity than Class selectors (.class), which in turn have higher specificity than Type selectors (element_name).color, display, width, height, border, margin, text-align.Flexbox Layout (display: flex):
display: flex.div children) are arranged in a row (flex-direction: row), do not wrap (flex-wrap: nowrap), and typically align to the start of the main axis and stretch along the cross axis. Margins, borders, and padding contribute to the item's total size within the layout.HTTP Request Methods:
method.Flask Application Structure:
Flask, request, render_template.app = Flask(__name__).app.run(debug=True).Routing:
@app.route() to associate URL paths with Python functions.<variable_name> (e.g., /user/<name>).<int:value>). If a URL segment cannot be converted to the specified type, Flask typically returns a 404 Not Found error./user/admin) will be matched over a dynamic route (e.g., /user/<name>) if the URL exactly matches the static path.Request Handling:
request.form.get("input_name") to retrieve values from submitted forms. Values are always strings.request.args.get("param_name", default_value) to retrieve values from the URL's query string (e.g., ?key=value). Values are always strings. A default value can be provided.request.method allows conditional logic based on the incoming request method (e.g., if request.method == "POST":).Template Rendering:
render_template("filename.html") to serve HTML templates.Error Handling:
try-except blocks are used for handling runtime exceptions that occur within the route function's logic (e.g., ZeroDivisionError). Note that route matching errors (like failed type conversion) are handled by Flask's routing layer, often resulting in a 404 Not Found.Data Types and Structures:
[]), adding elements (list.append(element)), accessing elements by index (list[index]).str(value)), f-strings for formatting (f"..."), string repetition ("text" * integer).int(value)).dict["key"]).Control Flow:
for loops: Iterating over iterable objects (lists, ranges).if/elif/else statements: Implementing conditional logic.sys Module:
sys.argv): sys.argv is a list containing the command-line arguments passed to a Python script. sys.argv[0] is the script name, and sys.argv[1:] is a list of all arguments after the script name. len(sys.argv) gives the total number of arguments.string.Template): A built-in Python module for simple string substitutions using $placeholder or ${placeholder} syntax.int(), float()) before performing mathematical operations, to prevent TypeError or unintended string operations (like repetition).Basic Syntax:
{{ variable_name }} (double curly braces).{% control_statement %} (curly brace-percentage sign).Control Flow:
for loops: {% for item in sequence %} and {% endfor %} for iterating over data.if/elif/else statements: {% if condition %}, {% elif condition %}, {% else %}, {% endif %} for conditional rendering.Filters:
variable | filter_name.sum (calculates sum of list elements), length (calculates length of a list/string), sort (sorts a list).sort(reverse=True) for descending order.Assignments:
set statement: {% set variable = expression %} for creating variables within the template.Bandwidth and Concurrent Requests:
Round Trip Time (RTT):
Information Theory (Data Encoding):