Home / Past papers / MAD1 Quiz 1 / this paper
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
Select the option which correctly matches the URL in column A with the rendered output in column B, if the application is running locally on http://127.0.0.1:5000.

```python
from flask import Flask, request
app = Flask(__name__)
@app.route('/calculate')
def calculate():
a = request.args.get('a')
b = request.args.get('b', 2)
c = request.args.get('c', "5")
try:
a = int(a)
b = int(b)
c = int(c)
except:
return "Invalid Input"
if a + b == c:
return f"Sum: {a+b}"
elif a * c == b:
return f"Product: {a*b}"
else:
return f"No match: {a+b+c}"
app.run(debug=True)
```
| URL | Output |
|---|---|
| 1. http://127.0.0.1:5000/calculate?a=3 | a. Sum: 6 |
| 2. http://127.0.0.1:5000/calculate?a=3&d=5 | b. Invalid Input |
| 3. http://127.0.0.1:5000/calculate?a=1&b=5 | c. Sum: 5 |
| 4. http://127.0.0.1:5000/calculate?a=1&b=5&c=6 | d. Product: 5 |
You are running a Flask web application locally using the command: python app.py. On which URL will the application be accessible in the browser?```python
from flask import Flask
app = Flask(__name__)
@app.route("/")
def port():
return "This is the same port question. Yet again, for a reason."
if __name__ == "__main__":
app.run(port=0007)
```
What will be the output when the code is executed?```python
from jinja2 import Template
temp = """
{% for num in seq | reject("even") -%}
{{ num + 2 }}
{%- endfor %}
"""
seq = [10, 3, 9, 8, 15]
output = Template(temp)
print(output.render(seq=seq))
```

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 ?
``` curl -i <URL> ```

``` curl -v <URL> ```

``` curl --headers <URL> ```

``` curl -X GET <URL> ```

```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;
}
```
Which substitution methods will work WITHOUT raising KeyError ?```python
from string import Template
template = Template("Hello $name, you have $count messages")
===substitution method code===
print(out)
```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 for the exam, followed by a knowledge graph.
The questions cover a broad range of topics within Modern Application Development, touching upon foundational Software Engineering principles, specific Python and Web Framework knowledge, Web Technologies (HTML, CSS), and basic Mathematical/Physics calculations.
Python Programming Essentials:
if-elif-else statements for conditional logic.try-except blocks for graceful management of potential runtime errors (e.g., during type conversion).Command-Line Arguments (sys.argv):
sys.argv is a list holding command-line arguments.sys.argv[0] contains the name of the script being executed.sys.argv are strings by default and require explicit type conversion if needed.String Templating (string.Template):
Template class for defining strings with placeholder variables (e.g., $variable).substitute() method: Performs substitution, raises KeyError if a placeholder is not provided.safe_substitute() method: Performs substitution, does not raise KeyError for missing placeholders; leaves them unchanged.Web Technologies (Frontend - HTML & CSS):
HTML Structure and Semantics:
<!DOCTYPE html>, <html>, <head>, <body>).<p>), divisions (<div>), hyperlinks (<a>), ordered lists (<ol>), list items (<li>).class, id, href. HTML attribute names are generally case-insensitive (though lowercase is best practice).CSS Styling and Layout:
p), Class (.highlight), ID (#special), and Descendant selectors (div p).background-color, width, padding, border, margin.display Property: Controls how an element interacts with the document flow.
display: block: Elements start on a new line and take up the full available width. height and width properties are effective.display: inline: Elements flow on the same line. height and width properties generally do not apply.display: inline-block: Elements flow on the same line but can be manipulated with height and width properties, and respect vertical padding/margin.CSS Box Model (Standard Model):
width and height properties, by default, refer to the content box.padding adds internal spacing between the content and the border.border is drawn around the padding.margin adds external spacing around the element, separating it from other elements; it does not contribute to the element's total rendered width or height but affects its position relative to other elements.Total Width = content_width + 2 * padding_left + 2 * padding_right + 2 * border_left + 2 * border_rightCharacter Encoding:
Web Backend Development (Flask & Jinja2):
Flask Framework:
@app.route()./<string:username>, /<int:post_id>).string, int). Mismatching types (e.g., non-integer for <int>) will result in a 404 Not Found error.?a=3&b=5) using request.args.get(). Understanding how to provide default values for missing parameters.app.run(). Specifying the listening port (e.g., port=0007). Default port is 5000. Understanding localhost (127.0.0.1) for local access and 0.0.0.0 for network-wide access.render_template() to send Python variables and data structures to Jinja2 templates for dynamic HTML generation.Jinja2 Templating Engine:
{% ... %} for control statements (loops, conditionals, variable assignments), {{ ... }} for outputting expressions/variables.for loops to iterate over lists or dictionaries. if-elif-else statements for conditional content.|reject("even") (to remove even numbers) or |sort (to sort a list).{% set variable = value %} to define variables within the template.user.id) or bracket notation (user['id'], user['name']).-%} (to remove trailing whitespace) and {%- (to remove leading whitespace) within template tags to prevent unwanted newlines or spaces in the rendered output.Web Application Concepts and Architecture:
Networking and Debugging Tools:
curl Command: A command-line tool for making HTTP requests.Debugging Flags:
-v (verbose): Provides detailed information about the request and response, including headers.-i (include): Includes HTTP response headers in the output.Basic Kinematics:
Time = Distance / SpeedDistance = Speed × TimeData Transfer Rate:
Data Transferred = Bandwidth × TimeUnit Conversions:
Data Units: Converting Megabits (Mbps) to Megabytes (MBps).
1 Byte = 8 bits. Therefore, 1 Megabyte (MB) = 8 Megabits (Mb).