10 questions · 33.5 marks · 7 papers. Try each one before checking.
Solve them and check answers →Read the notes first
24 Mar 2024
Question 7 MCQ · 3 marks
Consider the following Python code snippet.
from string import Template
text = "The $color car is parked in front of the $building."
template = Template(text)
print(=== OUTPUT ===)
Which of the following statements, when substituted in place of === OUTPUT ===, will throw a KeyError?
template.substitute({'color':'red'})template.substitute({'color': 'blue', 'building':'office', 'place': 'Chennai'})template.safe_substitute({'color':'green'})template.safe_substitute({'color':'yellow', 'building':'apartment', 'place': 'Chennai'})
16 Mar 2025
Question 6 MCQ · 3 marks
Consider the HTML code given below:
File name: base_layout.html
<!DOCTYPE html>
<html lang="en">
<head>
<title>ABC App</title>
</head>
<body>
<h3>Welcome to ABC App</h3>
{% block abc %}{% endblock %}
</body>
</html>
Which of the following is the correct implementation of template inheritance?
{% extends "base_layout.html" %}
{% block abc %}
<h4>Company Directors</h4>
<ul>
<li>Ram</li>
<li>Rahim</li>
<li>David</li>
</ul>
{% endblock %}
{% extends "base_layout.html" %}
{% block %}
<h4>Company Directors</h4>
<ul>
<li>Ram</li>
<li>Rahim</li>
<li>David</li>
</ul>
{% endblock %}
{% link template "base_layout.html" %}
{% block abc %}
<h4>Company Directors</h4>
<ul>
<li>Ram</li>
<li>Rahim</li>
<li>David</li>
</ul>
{% endblock %}
{% block "base_layout.html" %}
<h4>Company Directors</h4>
<ul>
<li>Ram</li>
<li>Rahim</li>
<li>David</li>
</ul>
{% endblock %}
03 Aug 2025
Question 8 MCQ · 3 marks
Consider the following Python code snippet.
from string import Template
msg = "The $lang programming language is $desc and $useful for web development."
template = Template(msg)
print(=== OUTPUT ===)
Which of the following statements, when substituted in place of === OUTPUT ===, will throw a KeyError?
template.substitute({'lang': 'Python'})template.substitute({'lang': 'Python', 'desc': 'popular', 'useful': 'useful'})template.safe_substitute({'lang': 'Python'})template.safe_substitute({'lang': 'Python', 'desc': 'versatile'})
Question 6 MCQ · 3 marks
Consider the following Flask and HTML implementations.
Flask file: main.py
from flask import Flask, render_template
app = Flask(__name__)
@app.route("/text/size/<int:size>/<color>")
def set_size(size, color):
style = {"font-size": str(size) + "px", "color": color}
return render_template("index.html", css_style=style)
app.run(debug=True)
HTML file: index.html
<!DOCTYPE html>
<html>
<div style="color: {{css_style['color']}}; font-size:{{css_style['font-size']}};">
IITM BS Degree Program
</div>
</html>
Assume that the Flask code is running on the server http://127.0.0.1:5000 without any errors. Choose the correct URL to render the output below.
[Image Description: Rendered text "IITM BS Degree Program" displayed in red font color at approximately 20px font size.]
- http://127.0.0.1:5000?text=red&size=20
- http://127.0.0.1:5000?size=20&text=red
- http://127.0.0.1:5000/text/size/red/20
- http://127.0.0.1:5000/text/size/20/red
14 Aug 2026
Question 7 MCQ · 3 marks
Consider the following Python jinja2 templating code.
File name: app.py
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?
- Nothing will be rendered in place of x
- 0
- 1
- 2
Question 9 MCQ · 5 marks
Consider the following Flask application structure and code.
my_app/
├── app.py
├── views/
│ └── index.html
├── templates/
│ ├── base.html
│ └── page.html
└── my_templates/
├── public/
│ └── home.html
└── private/
└── dashboard.html
app.py:
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)
Which of the following statements about the template rendering behavior is correct?
- All routes will work correctly as Flask searches both templates/ and my_templates/
- Only /dashboard and /view routes work, while / and /page routes fail with TemplateNotFound Error
- The / and /dashboard routes work, while /view and /page fail with TemplateNotFound Error
- All routes fail because Flask requires templates to be in a default folder
July 2022
Question 15 MCQ · 4.5 marks
Consider the following PyHTML program. Identify the corresponding HTML file which will be generated on running the PyHTML code.
from pyhtml import *
my_html = html (head (title("Quiz 2")),
body (h2("Second level heading"),
div("This is my first div"),
p("Paragraph1"),
p("Paragraph2")
)
)
output = my_html.render()
print (output)
<!DOCTYPE html>
<html>
<head>
<title>Quiz 2</title>
</head>
<body>
<h2>Second level heading</h2>
<div>This is my first div</div>
<p>Paragraph1</p>
<p>Paragraph2</p>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<h2>Second level heading</h2>
</head>
<body>
<title>Quiz 2</title>
<div>This is my first div</div>
<p>Paragraph1</p>
<p>Paragraph2</p>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<title>Quiz 2</title>
<div>This is my first div</div>
</head>
<body>
<h2>Second level heading</h2>
<p>Paragraph1</p>
<p>Paragraph2</p>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<title>Quiz 2</title>
</head>
<body>
<h2>Second level heading</h2>
<div>This is my first div
<p>Paragraph1</p>
<p>Paragraph2</p>
</div>
</body>
</html>
Question 7 MCQ · 3 marks
If the below flask application is running locally on the URL: ‘http://127.0.0.1:5000’, what will be rendered by the browser?
Python file: main.py
from flask import Flask, render_template
app=Flask(__name__)
@app.route('/')
def home():
my_course = ['App1', 'App2', 'python', 'Data science', 'Database', 'machine learning']
return render_template('index.html', list=my_course)
if __name__ == '__main__':
app.run(debug=True)
Template: index.html
<html>
<head>
<title>template file</title>
</head>
<body>
{% macro display (list) %}
{% for course in list %}
<p>{{ course }}</p>
{% endfor %}
{% endmacro %}
{{ display(list) }}
</body>
</html>
['App1',
'App2',
'python',
'Data science',
'Database',
'machine learning']
['App1', 'App2', 'python', 'Data science', 'Database',
'machine learning']
App1
App2
python
Data science
Database
machine learning
App1 App2 python Data science Database machine learning
Dec 2023
Question 7 MCQ · 2 marks
Consider the following python code snippet.
from string import Template as T1
from jinja2 import Template as T2
temp = "A student needs to complete $c1 level to get to the {{c2}} level."
temp = T1(temp)
out = temp.substitute({'c1': 'foundation', 'c2': 'diploma'})
print(out)
out = T2(out)
print(out.render({'c2':'diploma'}))
What is the generated output on python console?
- A student needs to complete foundation level to get to the diploma level.A student needs to complete foundation level to get to the diploma level.
- A student needs to complete $c1 level to get to the {{c2}} level.A student needs to complete foundation level to get to the diploma level.
- A student needs to complete foundation level to get to the {{c2}} level.A student needs to complete foundation level to get to the diploma level.
- A student needs to complete foundation level to get to the {{diploma}} level.A student needs to complete foundation level to get to the diploma level.
06 Apr 2026
Question 11 MCQ · 4 marks
Consider the following HTML and Python Flask code.
Filename: app.py
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
<!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?
- Output is: 3
- Output is:
- Output is: 1 2 3
- Output is: 1 2 3 3
Check your answers →
Weeks covering this topic
Other MAD 1 topics