Flask: Develop Web Applications in Python Educative Quiz Answers

Get Flask: Develop Web Applications in Python Educative Quiz Answers

This project-based course is a detailed guide to web application development using the increasingly popular Flask framework.

Flask is known for being simple, lightweight and having a small learning curve. If you’ve got some experience in Python, picking up Flask will be a breeze. It’s got a booming job market and will put you on track to becoming an in-demand full-stack developer. What’s not to love?

Enroll on Educative

Quiz 1: Introduction to Flask

Q1. Why is Flask called a Microframework?

  • Because it is a light-weight framework
  • Because it has all the necessary modules to create a full-fledged application like authentication, ORM, and so on.
  • Because it only contains the bare basic necessaties of a web application like routing, request handling, sessions and so on
  • Both A and C
  • None of the above

Q2. How do the Client and Server interact with each other over the Internet?

  • They communicate using the transmission of data.
  • They do not communicate with eachother.
  • They communicate using the HTTP and HTTPS protocols

Q3. What is the functionality of a View in the MVC architecture?

  • Views are the components that act as an interface between models and templates.
  • Views are the components that are visible to the user, such as the (GUI)
  • Views are the component of web application that takes care of data manipulation inside the database
  • None of the above.

Q4. What is the functionality of a Model in the MTV and MVC architectures?

  • Models are the components that define the mapping of data in the database
  • Models are the components that are visible to the user, such as the (GUI).
  • Models are the component of web application that takes care of data manipulation inside the database
  • None of the above

Q5. What do we use Jinja for?

  • We use it to send data from server to the client
  • We use Jinja to create dynamic templates
  • We use Jinja to host our application on the production server
  • None of the above

Quiz 2: First Flask Application

Q1. In the application given below, which URL must the user visit for the string “Join our Community!”

from flask import Flask
app = Flask(__name__)

@app.route("/")
def  home():
    return "Welcome!"

@app.route("/join")
def join():
    return "Join our Community!"
  
@app.route("/login")
def join():
    return "Login to our portal."

if __name__ == "__main__":
    app.run(debug=True, host="0.0.0.0", port=3000)
  • <Application_URL>
  • <Application_URL>/
  • <Application_URL>/join
  • <Application_URL>/login

Q2. Which of the following routes can be associated with the test view function such that it does not raise an error?

from flask import Flask
app = Flask(__name__)


def  test(name):
    return "I am" + name

if __name__ == "__main__":
    app.run(debug=True, host="0.0.0.0", port=3000)
  • Option 1
@app.route("/")
  • Option 2
@app.route("/<name>")
  • Option 3
@app.route("/test")
  • Option 4
@app.route("/<int:name>")

Q3. What should be the return statement of the show_cube() function in the application given below.

from flask import Flask
app = Flask(__name__)


@app.route('/square/<int:number>')
def show_cube(number):
    """View that shows the cube of the number passed by URL"""
    


if __name__ == "__main__":
    app.run(debug=True, host="0.0.0.0", port=3000)
  • Option 1
return"Cube of "+number+" is: "+ (number*number*number)
  • Option 2
return"Cube of "+ str(number) +" is: "+ str(number*number*number) 
  • Option 3
return"Cube of "+number+" is: "+ int(number)*int(number)*int(number)
  • None of the above

Quiz 3: Static Templates

Q1. Which of the following will produce a centered heading “Hello World”?

  • Option 1
<p style="text-align: center">Hello World</p>
  • Option 2
<h1 style="text-align: center">Hello World<h1>
  • Option 3
<h1>Hello World<h1>

Q2. To be rendered, an HTML template file should be placed in which subdirectory of the web application?

  • assets
  • images
  • templates

Q3. The HTML templates are rendered using which of the following function call?

  • render_html()
  • print()
  • render_template()
  • None of the above

Quiz 4: Static Files

Q1. What are static files or assests?

  • Static file is another name for a static template
  • Static files are the CSSJS, images or similar files which are sent to the client without server intervention
  • Static files or assets are the files that the client uploads on the server

Q2. What is the url_for() function used for?

  • This function is an alternative for the route() decorator
  • It is used to return the URL for the home directory of a web application
  • It is used to lookup the URL corresponding to an IP address
  • It is used to generate absolute URLs for endpoints

Q3. Which one of these is the correct syntax for including a CSS style sheet in the template?

  • Option 1
<link rel="stylesheet" href= url_for('static', filename='borders.css') /> 
  • Option 2
<link rel="stylesheet" href="url_for('static', filename='borders.css')" />
  • Option 3
<link rel="stylesheet" href= {{"url_for('static', filename='borders.css')"}} />
  • Option 4
<link rel="stylesheet" href="{{url_for('static', filename='borders.css')}}" /> 

Quiz 5: Variables

Q1. Which one of these statements will print the first index of a list called arr.

  • Option 1
{ arr[0] }
  • Option 2
{{ arr[0] }}
  • Option 3
{% arr[0] %}

Quiz 6: Template Inheritance

Q1. Which of these statements do we use in the child templates to inherit them from base.html?

  • Option 1
{% inherits "base.html" %}
  • Option 2
{% parent "base.html" %}
  • Option 3
{% extends "base.html" %}
  • Option 4
{% block "base.html" %}

Quiz 7: Data Handling Using the Request Object

Q1. Which of these if statements can determine if a POST request was received?

  • Option 1
if method.post:
  ...
  • Option 2
if method == "POST":
  ...
  • Option 3
if request.post:
  ...
  • Option 4
if request.method == "POST":
  ...

Quiz 8: Form Validation and Data and Error Handling with Flask-WTF

Q1. The method form.validate_on_submit() is a shortcut method for which of these functions?

  • form.is_submitted() and form.is_valid()
  • form.is_submitted() and form.validate()
  • form.is_submitted() and form.errors()
  • form.validate() and form.errors()

Quiz 9: The One-to-One Relationship

Q1. What is the type of the relationship which exists between Entity1 and Entity2 in the snippet given below?

class Entity1(db.Model):
    id = db.Column(db.Integer, primary_key = True)
    column1 = db.Column(db.String, db.ForeignKey('entity2.id'))
        
class Entity2(db.Model):
    id = db.Column(db.String(50), primary_key=True)
    column2 = db.relationship('Entity1', backref='column3', uselist=True)
  • One-to-Many relationship
  • Many-to-Many relationship
  • One-to-One relationship

Quiz 10: Retrieval

Q1. You are given the following model class:

class Student(db.Model):
    roll_number = db.Column(db.Integer, primary_key = True, unique = True)
    name = db.Column(db.String, nullable = False)
    batch = db.Column(db.String, nullable = False)

Which of these queries will return all elements of the Student model having the batch column equal to "2015" and a name that ends with "ah".

  • Option 1
Student.query.filter(batch = "2015").filter_by(Student.name.endswith("ah")).first()
  • Option 2
Student.query.filter(batch = "2015").filter_by(Student.name.endswith("ah")).all()
  • Option 3
Student.query.filter_by(batch = "2015").filter(Student.name.endswith("ah"))
  • Option 4
Student.query.filter_by(batch = "2015").filter(Student.name.endswith("ah")).all()
Conclusion:

I hope this Flask: Develop Web Applications in Python Educative Quiz Answers would be useful for you to learn something new from this problem. If it helped you then don’t forget to bookmark our site for more Coding Solutions.

This Problem is intended for audiences of all experiences who are interested in learning about Data Science in a business context; there are no prerequisites.

Keep Learning!

More Coding Solutions >>

LeetCode Solutions

Hacker Rank Solutions

CodeChef Solutions

Leave a Reply

Your email address will not be published.