MauryaHub PYQ Practice

Application Development - 1 · Quiz 2 · Jan 2025

Application Development - 1 · Quiz 2 · Jan 2025

← Course papers · Start practice / exam

Questions and published explanations below are available without starting a test. Some questions may not have a published solution yet.

16 / 16 published solutions

Question 48 MCQ · 2.0 marks

Source diagram or notation
6406533954588.
NoSQL (Document-based database like MongoDB)
6406533954589.
Graph Database (e.g., Neo4j)
6406533954590.
RDBMS (e.g., PostgreSQL, MySQL, SQLite)
6406533954591.
Key-Value Store (e.g., Redis, DynamoDB)

Published solution

Let us evaluate the institution's database requirements: **1. Structured Entities and Relationships:** Managing students, courses, faculty assignments, prerequisites, and grades across semesters involves highly structured, interrelated tabular data with foreign-key constraints. **2. Transactional Integrity (ACID Compliance):** Handling course enrollments, fee payments, refunds, and secure grade transcripts requires strict **ACID** (Atomicity, Consistency, Isolation, Durability) transactions and role-based access control. **3. Conclusion:** A **Relational Database Management System (RDBMS)** such as PostgreSQL, MySQL, or SQLite is specifically designed for structured relational schemas, referential integrity, and ACID transactions. **Answer: RDBMS (e.g., PostgreSQL, MySQL, SQLite).** A: **Incorrect:** Document-based NoSQL databases are suited for flexible, semi-structured documents rather than strict relational schemas and multi-table financial/academic transactions. B: **Incorrect:** Graph databases specialize in traversing complex network topologies (like social networks), not general transactional student-enrollment and fee-payment systems. C: **Correct:** An RDBMS provides structured relational tables, foreign-key constraints, and ACID transactions required for enrollments, prerequisites, grades, and payments. D: **Incorrect:** Key-value stores are designed for fast simple lookups and caching, not complex relational queries across multiple entities.

Report a correction for Q48

Question 49 MCQ · 2.0 marks

Which of the following best describes the primary advantage of asynchronous updates in web applications?
6406533954592.
It ensures that all elements of a web page are loaded at the same time.
6406533954593.
It improves performance by allowing parts of a webpage to update without requiring a full reload.
6406533954594.
It forces the client to wait until the server responds before interacting with the page.
6406533954595.
It requires a high-speed internet connection to function correctly.

Published solution

**Asynchronous updates** in web applications (commonly implemented using AJAX / `fetch()` / `XMLHttpRequest`) allow the browser to send and receive data from the server in the background. **Primary Advantage:** Instead of reloading the entire HTML document on every user action, the web application can fetch only the required data and dynamically update specific parts of the DOM. This reduces network overhead, improves responsiveness, and provides a smooth user experience. **Answer: It improves performance by allowing parts of a webpage to update without requiring a full reload.** A: **Incorrect:** Asynchronous updates fetch data on demand in the background rather than forcing all elements to load simultaneously. B: **Correct:** Asynchronous updates allow specific sections of a webpage to be updated dynamically without a full page reload. C: **Incorrect:** Blocking the client until the server responds describes *synchronous* communication, not asynchronous updates. D: **Incorrect:** Asynchronous updates actually save bandwidth by transferring only small payloads (such as JSON) instead of full HTML pages.

Report a correction for Q49

Question 50 MCQ · 2.0 marks

Source diagram or notation
6406533954596.
1-c, 2-d, 3-b, 4-a
6406533954597.
1-c, 2-b, 3-d, 4-a
6406533954598.
1-c, 2-d, 3-a, 4-b
6406533954599.
1-a, 2-d, 3-b, 4-c

Published solution

Let us match each numbered item on the left with its correct definition on the right: - **1. GET, POST, PUT, DELETE** \( \rightarrow \) **c. HTTP request method**: These are standard HTTP verbs used by clients to specify the desired action on a resource. - **2. Client-Server Model** \( \rightarrow \) **d. Explicit differentiation between clients and servers**: A distributed architecture that separates service requesters (clients) from service providers (servers). - **3. Software Architecture Pattern** \( \rightarrow \) **b. MVC**: Model-View-Controller (MVC) is a classic software architectural pattern. - **4. Internet Protocol** \( \rightarrow \) **a. a set of standards for addressing and routing data on the Internet**: IP defines how packets are addressed and routed across networks. Thus, the correct matching is **1-c, 2-d, 3-b, 4-a**. **Answer: 1-c, 2-d, 3-b, 4-a.** A: **Correct:** 1 matches c (HTTP request methods), 2 matches d (Client-Server differentiation), 3 matches b (MVC pattern), and 4 matches a (Internet Protocol). B: **Incorrect:** Client-Server Model (2) is not MVC (b), and Software Architecture Pattern (3) is not client-server differentiation (d). C: **Incorrect:** Software Architecture Pattern (3) corresponds to MVC (b), not routing standards (a). D: **Incorrect:** GET, POST, PUT, DELETE (1) are HTTP request methods (c), not Internet Protocol routing standards (a).

Report a correction for Q50

Question 51 MCQ · 3.0 marks

Source diagram or notation
6406533954600.
25
6406533954601.
125
6406533954602.
[0, 1, 4, 27, 16]
6406533954603.
[0, 1, 8, 9, 64]

Published solution

Let us trace the Python decorator `@update` applied to `func(N)`: **1. How the Decorator Replaces `func`:** Writing `@update` above `def func(N):` is equivalent to `func = update(func)`. Therefore, calling `func(5)` actually calls `wrapper(5)`! Notice that `wrapper(N)` never even calls the original `func`; it computes and returns the list `out` directly. **2. Tracing `wrapper(5)`:** `for i in range(5):` iterates over `i = 0, 1, 2, 3, 4`: - `i = 0` (`0 % 2 == 0`, even): appends `0**3 = 0`. - `i = 1` (`1 % 2 != 0`, odd): appends `1**2 = 1`. - `i = 2` (`2 % 2 == 0`, even): appends `2**3 = 8`. - `i = 3` (`3 % 2 != 0`, odd): appends `3**2 = 9`. - `i = 4` (`4 % 2 == 0`, even): appends `4**3 = 64`. Thus, `wrapper(5)` returns `[0, 1, 8, 9, 64]`, which is printed. **Answer: [0, 1, 8, 9, 64].** A: **Incorrect:** `25` (`5**2`) is not returned because `@update` replaces `func` with `wrapper`, which returns a list. B: **Incorrect:** `125` (`5**3`) is what the undecorated `func(5)` would return, but `@update` replaces `func` with `wrapper`. C: **Incorrect:** `[0, 1, 4, 27, 16]` squares even numbers and cubes odd numbers, which is the opposite of `if i%2 == 0: out.append(i**3)`. D: **Correct:** `wrapper(5)` cubes even indices (`0, 8, 64`) and squares odd indices (`1, 9`), returning `[0, 1, 8, 9, 64]`.

Report a correction for Q51

Question 52 MCQ · 3.0 marks

Source diagram or notation
6406533954604.Source diagram or notation
6406533954605.Source diagram or notation
6406533954606.Source diagram or notation
6406533954607.Source diagram or notation

Published solution

In Jinja2 (used by Flask), **template inheritance** allows a child template to extend a base layout template and override named blocks. **1. Extending the Base Template:** The child template must start with `{% extends "base_layout.html" %}`. **2. Overriding the Named Block:** In `base_layout.html`, the placeholder block is defined as `{% block abc %}{% endblock %}`. To inject content into this block, the child template must specify the exact block name `abc`: `{% block abc %} ... {% endblock %}`. Option A uses both `{% extends "base_layout.html" %}` and `{% block abc %} ... {% endblock %}`. **Answer: Option A ({% extends "base_layout.html" %} with {% block abc %}).** A: **Correct:** Uses `{% extends "base_layout.html" %}` and overrides the named block `{% block abc %} ... {% endblock %}`. B: **Incorrect:** `{% block %}` is missing the required block name `abc`. C: **Incorrect:** `{% link template ... %}` is not valid Jinja2 syntax; template inheritance requires `{% extends ... %}`. D: **Incorrect:** `{% block "base_layout.html" %}` is invalid because `{% extends "base_layout.html" %}` is required to inherit from a base template.

Report a correction for Q52

Question 53 MCQ · 3.0 marks

Source diagram or notation
6406533954608.Source diagram or notation
6406533954609.Source diagram or notation
6406533954610.Source diagram or notation
6406533954611.Source diagram or notation

Published solution

Let us examine the Flask route definition and how query parameters work: **1. Route Path Matching:** The route is decorated with `@app.route("/response")` (without a trailing slash or path parameter). In Flask, a route defined without a trailing slash (`/response`) only matches `/response`, whereas `/response/` or `/response/n=6` will result in a **404 Not Found** error. **2. Query String Syntax (`request.args.get("n")`):** `request.args` parses URL **query parameters**, which follow a question mark `?` after the path: `/response?n=6`. - Using `/response&n=6` treats `response&n=6` as the URL path (since there is no `?`), which does not match `/response` and throws **404 Not Found**. - Therefore, only `http://127.0.0.1:5000/response?n=6` matches the `/response` route and passes `n=6` via `request.args`. **Answer: http://127.0.0.1:5000/response?n=6.** A: **Incorrect:** `/response/n=6` treats `/n=6` as a sub-path, which is not defined in `@app.route("/response")` and throws a 404 Not Found error. B: **Incorrect:** Because `@app.route("/response")` is defined without a trailing slash, requesting `/response/` with a trailing slash returns a 404 Not Found error. C: **Incorrect:** Query strings must start with `?`, not `&`. Without `?`, `/response&n=6` is treated as the path name and returns 404 Not Found. D: **Correct:** `http://127.0.0.1:5000/response?n=6` routes to `/response` and passes `n=6` in the query string (`request.args`).

Report a correction for Q53

Question 54 MCQ · 3.0 marks

A web server is handling requests and has an 8-core processor, 32 GB of RAM, and a network bandwidth of 500 Mbps. The application running on the server is capable of generating 100 HTML pages every second. Each of these pages includes an image file that is 500 KB in size. What is the maximum number of requests per second that the server can handle?
6406533954612.
100 requests/sec
6406533954613.
125 requests/sec
6406533954614.
250 requests/sec
6406533954615.
400 requests/sec

Published solution

To find the maximum number of requests per second the server can handle, we must check both the **application generation capacity** and the **network bandwidth capacity**, and take the bottleneck (minimum) of the two: **1. Application Generation Limit:** The problem states that the application is capable of generating **100 HTML pages every second**. **2. Network Bandwidth Limit:** - Network bandwidth \( = 500\text{ Mbps} \). - Size per page (image) \( = 500\text{ KB} = 500 \times 8\text{ Kb} = 4000\text{ Kb} = 4\text{ Mb} \). - Network capacity \( = \frac{500\text{ Mbps}}{4\text{ Mb/request}} = 125\text{ requests/sec} \). **3. Overall Bottleneck:** Since the application can only generate 100 pages/sec while the network can transmit 125 pages/sec, the server is bottlenecked by the application at **100 requests/sec**: \[ \text{Max Requests/sec} = \min(100, 125) = 100\text{ requests/sec} \] **Answer: 100 requests/sec.** A: **Correct:** Although the 500 Mbps network can transfer 125 pages/sec (at 500 KB = 4 Mb each), the application itself can only generate 100 HTML pages/sec, limiting the server to 100 requests/sec. B: **Incorrect:** 125 requests/sec is the network bandwidth limit (`500 Mbps / 4 Mb`), which exceeds the application's 100 pages/sec generation limit. C: **Incorrect:** Exceeds both the application limit (100/sec) and network limit (125/sec). D: **Incorrect:** Exceeds both the application limit (100/sec) and network limit (125/sec).

Report a correction for Q54

Question 55 MCQ · 3.0 marks

The lens of an HDD can read data on the rotating disk with the speed of 36,000 bits per second. The disk is designed such that 600 bits pass under the lens for every revolution of the disk. What should be the maximum speed of the disk so that the lens does not miss any data?
6406533954616.
60 RPM
6406533954617.
100 RPM
6406533954618.
3600 RPM
6406533954619.
6000 RPM

Published solution

Let us calculate the maximum rotational speed in **RPM (Revolutions Per Minute)** step by step: **1. Find the Maximum Revolutions Per Second (RPS):** - The lens reads at a maximum speed of \( 36,000\text{ bits/second} \). - Every revolution of the disk passes \( 600\text{ bits} \) under the lens. - Therefore, the maximum number of revolutions per second is: \[ \text{RPS} = \frac{36,000\text{ bits/sec}}{600\text{ bits/revolution}} = 60\text{ revolutions/second} \] **2. Convert Revolutions Per Second (RPS) to Revolutions Per Minute (RPM):** Since there are \( 60\text{ seconds} \) in \( 1\text{ minute} \): \[ \text{RPM} = 60\text{ rev/sec} \times 60\text{ sec/min} = 3600\text{ RPM} \] **Answer: 3600 RPM.** A: **Incorrect:** 60 is the number of revolutions per *second* (RPS), not per *minute* (RPM). B: **Incorrect:** Does not match the ratio `36,000 / 600 * 60`. C: **Correct:** At 60 revolutions per second (`36,000 / 600`), the speed in revolutions per minute is `60 * 60 = 3600 RPM`. D: **Incorrect:** At 6000 RPM (100 RPS), `100 * 600 = 60,000 bits/sec` would pass under the lens, exceeding its 36,000 bits/sec limit.

Report a correction for Q55

Question 56 MCQ · 4.5 marks

Source diagram or notation
6406533954620.
1-ii, 2-i, 3-iii, 4-iv, 5-v
6406533954621.
1-iii, 2-iii, 3-iii, 4-v, 5-iv
6406533954622.
1-ii, 2-i, 3-i, 4-iv, 5-v
6406533954623.
1-ii, 2-iii, 3-i, 4-iii, 5-iii

Published solution

Let us trace how Flask-RESTful routes each of the 5 request URLs: **Registered Routes:** - `my_resource1` is mapped to `"/"`. - `my_resource2` is mapped to `"/<int:x>/<int:y>"` (which requires two integer path segments). **Evaluating Each URL:** - **1) `http://127.0.0.1:5000/`**: Matches `my_resource1` (`"/"`), which returns `{"output": "Default computed value : 0"}` \( \rightarrow \) **ii**. - **2) `http://127.0.0.1:5000/x=6/y=2`**: The segments `'x=6'` and `'y=2'` are not valid integers for `<int:x>/<int:y>`, so it returns `Not Found` \( \rightarrow \) **iii**. - **3) `http://127.0.0.1:5000/6/2`**: Matches `my_resource2` with `x = 6, y = 2`, computing `6**2 = 36` and returning `{"output": "Computed x^y =36"}` \( \rightarrow \) **i**. - **4) `http://127.0.0.1:5000/6`**: Only has one integer segment instead of two, so it matches no route and returns `Not Found` \( \rightarrow \) **iii**. - **5) `http://127.0.0.1:5000/2`**: Only has one integer segment instead of two, so it matches no route and returns `Not Found` \( \rightarrow \) **iii**. Thus, the correct matching is **1-ii, 2-iii, 3-i, 4-iii, 5-iii**. **Answer: 1-ii, 2-iii, 3-i, 4-iii, 5-iii.** A: **Incorrect:** URL 2 (`/x=6/y=2`), URL 4 (`/6`), and URL 5 (`/2`) do not match `/<int:x>/<int:y>` and all return `Not Found` (iii). B: **Incorrect:** URL 1 (`/`) matches `my_resource1` and returns ii, while URL 3 (`/6/2`) returns i. C: **Incorrect:** URL 2 (`/x=6/y=2`) fails the `<int:x>` converter because `'x=6'` is not an integer, and URLs 4 and 5 lack a second integer parameter. D: **Correct:** URL 1 returns ii, URL 3 returns i, and URLs 2, 4, and 5 do not match any route and return iii (`Not Found`).

Report a correction for Q56

Question 57 MCQ · 4.5 marks

Source diagram or notation
6406533954624.Source diagram or notation
6406533954625.Source diagram or notation
6406533954626.Source diagram or notation
6406533954627.Source diagram or notation

Published solution

Let us trace the Flask-SQLAlchemy query and update operations step by step: **1. Fetching `student1`:** `student1 = Student.query.filter_by(First_name="Karthik").first()` - In the `students` table, rows 2, 6, and 7 have `First_name = "Karthik"`. - Calling `.first()` retrieves **only the first matching record**, which is row 2 (`ID = 2`, `Karthik Kumar`). **2. Updating and Committing:** - `student1.First_name = "Vikram"` changes the `First_name` of row 2 (`ID = 2`) from `Karthik` to `Vikram`. - `db.session.commit()` saves this change to the database. Rows 6 (`Karthik Ramesh`) and 7 (`Karthik Kumar`) remain unchanged. **3. Printing All Students:** Iterating over `Student.query.all()` prints: - `Arjun Kumar` - `Vikram Kumar` (updated from Karthik Kumar) - `Pranav Kumar` - `Surya ` - `Harish Vignesh` - `Karthik Ramesh` - `Karthik Kumar` **Answer: Option C (only the first Karthik Kumar is updated to Vikram Kumar).** A: **Incorrect:** Row 2 (`Karthik Kumar`) was updated to `Vikram Kumar` and committed to the database. B: **Incorrect:** `.first()` only returns the first matching record (ID 2), so rows 6 and 7 are not updated to `Vikram`. C: **Correct:** `.first()` selects only the first record with `First_name == 'Karthik'` (ID 2), updating it to `Vikram Kumar` while leaving rows 6 and 7 as `Karthik`. D: **Incorrect:** `Student.query.all()` retrieves all 7 rows in the table, not just the rows that originally had `Karthik`.

Report a correction for Q57

Question 58 MSQ · 2.0 marks

Source diagram or notation
6406533954628.Source diagram or notation
6406533954629.Source diagram or notation
6406533954630.Source diagram or notation
6406533954631.Source diagram or notation

Published solution

Let us analyze the route `@app.route("/user/<id>")`: **1. How `<id>` Matches URLs:** In Flask, `<id>` (without a type converter) is a **string converter** (`<string:id>`) that matches any text without a slash (`/`) following `/user/`. **2. Testing Each URL:** - **Option A (`http://127.0.0.1:5000/user/2001`)**: Matches `/user/<id>` with `id = '2001'`. Returns `"User Id : 2001"` (200 OK). - **Option B (`http://127.0.0.1:5000/user/id=2001`)**: Since `<id>` accepts any string without a slash, `'id=2001'` is valid! It matches `/user/<id>` with `id = 'id=2001'` and returns `"User Id : id=2001"` (200 OK). - **Option C (`http://127.0.0.1:5000/id=2001`)**: Missing the `/user/` prefix, so it does not match `/user/<id>` and renders **Not Found (404)**. - **Option D (`http://127.0.0.1:5000/2001`)**: Missing the `/user/` prefix, so it does not match `/user/<id>` and renders **Not Found (404)**. **Answer: http://127.0.0.1:5000/id=2001 and http://127.0.0.1:5000/2001 (Options C and D).** A: **Incorrect:** Matches `/user/<id>` with `id = '2001'` and succeeds without error. B: **Incorrect:** Because `<id>` defaults to a string parameter, `'id=2001'` matches `<id>` and does not throw a Not Found error. C: **Correct:** The URL `/id=2001` lacks the `/user/` prefix required by `@app.route("/user/<id>")`, resulting in a Not Found error. D: **Correct:** The URL `/2001` lacks the `/user/` prefix required by `@app.route("/user/<id>")`, resulting in a Not Found error.

Report a correction for Q58

Question 59 MSQ · 3.0 marks

Source diagram or notation
6406533954632.Source diagram or notation
6406533954633.Source diagram or notation
6406533954634.Source diagram or notation
6406533954635.Source diagram or notation

Published solution

Let us trace what happens when requesting `http://127.0.0.1:5000/endpoint/user1/developer`: **1. Route Matching:** The route `@app.route('/endpoint/<username>')` uses the default `string` converter for `<username>`, which **does not match slashes (`/`)** (unlike `<path:username>`). Because `/endpoint/user1/developer` has an extra `/developer` segment, no route matches and Flask triggers the **404 error handler**. **2. Custom Error Handler Execution:** ```python @app.errorhandler(404) def notfound(error): return {"message": "invalid endpoint!"} ``` - The function returns the dictionary `{"message": "invalid endpoint!"}` **without specifying a status code tuple** (i.e. it did not write `return {...}, 404`). - In Flask, whenever a view or error handler returns a dictionary/response without an explicit status code, the HTTP status code defaults to **200 OK**! **Answer: The output on the browser will be {"message": "invalid endpoint!"} and the status code of the response will be 200 (Options B and C).** A: **Incorrect:** `<username>` does not match paths containing `/`, so `/endpoint/user1/developer` does not match `func(username)`. B: **Correct:** The unmatched URL triggers the `@app.errorhandler(404)` function, which returns `{"message": "invalid endpoint!"}`. C: **Correct:** Because `notfound(error)` returns `{"message": "invalid endpoint!"}` without `, 404`, Flask assigns the default HTTP status code `200`. D: **Incorrect:** A custom `@app.errorhandler(404)` must explicitly return `, 404` to set a 404 status code; otherwise Flask defaults to 200.

Report a correction for Q59

Question 60 MSQ · 3.0 marks

Source diagram or notation
6406533954636.
sales_man= Salesman.query.filter((Salesman.sales_amount >= 5000) & (Salesman.sales_amount <= 10000)).all()
6406533954637.
sales_man= Salesman.query.filter(and_(Salesman.sales_amount >= 5000, Salesman.sales_amount <= 10000)).all()
6406533954638.
sales_man= Salesman.query.filter(sales_amount >= 5000 and sales_amount <= 10000)
6406533954639.
sales_man= Salesman.query.filter_by(sales_amount >= 5000, sales_amount <= 10000)

Published solution

Let us check each Flask-SQLAlchemy query for retrieving `Salesman` records where `sales_amount` is between 5000 and 10000 (inclusive): **1. Bitwise `&` inside `.filter()` (Option A):** `Salesman.query.filter((Salesman.sales_amount >= 5000) & (Salesman.sales_amount <= 10000)).all()` SQLAlchemy overloads the bitwise `&` operator on column expressions (`Salesman.sales_amount`) to generate a SQL `AND` clause. This is valid and correct. **2. `and_()` inside `.filter()` (Option B):** `Salesman.query.filter(and_(Salesman.sales_amount >= 5000, Salesman.sales_amount <= 10000)).all()` Using SQLAlchemy's `and_()` function (or passing comma-separated conditions to `.filter()`) on `Salesman.sales_amount` is also valid and correct. **3. Why Options C and D are Invalid:** - Option C uses bare `sales_amount` (which raises a `NameError` because it is not prefixed with the model class `Salesman.`) and uses Python's short-circuit `and` keyword. - Option D uses `.filter_by()`, which only accepts keyword equality arguments (`key=value`), not inequality expressions (`>=`, `<=`). **Answer: Options A and B.** A: **Correct:** Uses `Salesman.sales_amount` with parenthesized inequality expressions combined via SQLAlchemy's overloaded `&` operator. B: **Correct:** Uses `and_(Salesman.sales_amount >= 5000, Salesman.sales_amount <= 10000)` inside `.filter()`. C: **Incorrect:** `sales_amount` is not defined in the local scope (must be `Salesman.sales_amount`), and Python's `and` cannot be used to combine SQLAlchemy column expressions. D: **Incorrect:** `.filter_by()` only accepts keyword equality arguments (`column=value`), not comparison operators like `>=` or `<=`.

Report a correction for Q60

Question 61 MSQ · 3.0 marks

Source diagram or notation
6406533954640.Source diagram or notation
6406533954641.Source diagram or notation
6406533954642.Source diagram or notation
6406533954643.Source diagram or notation

Published solution

Let us evaluate each statement against the given Flask routes: - **Option A (`http://127.0.0.1:5000/user/John`)**: Matches `@app.route('/user/<name>')` with `name = 'John'` and returns `"Hello, John!"`. (**Correct**) - **Option B (`http://127.0.0.1:5000/user/07`)**: Since `<name>` is a string parameter, `name = '07'` is valid and returns `"Hello, 07!"`, **not** `"Hello, !"`. (**Incorrect**) - **Option C (`http://127.0.0.1:5000/profile/10`)**: Matches `@app.route('/profile/<int:user_id>')` with `user_id = 10` and returns `"User Profile ID: 10"`. (**Correct**) - **Option D (`http://127.0.0.1:5000/user/`)**: Because `/user/<name>` requires a non-empty `<name>` segment and there is no route registered for `/user/`, accessing `/user/` returns a **404 Not Found** error. (**Correct**) **Answer: Options A, C, and D.** A: **Correct:** `/user/John` matches `/user/<name>` with `name='John'` and returns `Hello, John!`. B: **Incorrect:** `/user/07` passes `'07'` as the string `name` and returns `Hello, 07!`, not `Hello, !`. C: **Correct:** `/profile/10` matches `/profile/<int:user_id>` with `user_id=10` and returns `User Profile ID: 10`. D: **Correct:** `/user/` has no `<name>` argument and no matching route, resulting in a 404 error.

Report a correction for Q61

Question 62 MSQ · 4.5 marks

Consider the following Flask-RESTful API implementation: from flask import Flask, request from flask_restful import Resource, Api app = Flask(__name_) api = Api(app) students = { 1: {"name": "Arjun", "grade": "A"}, 2: {"name": "Kiran", "grade": "B+"}, 3: {"name": "Meera", "grade": "A"}, } class Student (Resource) : def get(self, student_id): if student_id in students: return students[student_id], 200 return {"message": "Student not found"}, 404 def put(self, student_id): data = request. json if student_id in students: students[student_id]["grade"] = data.get("grade", students[student_id]["grade"]) return {"message": "Student record updated", “student”: students[student_id]}, 200 return {"message": "Student not found"}, 404 api.add_resource(Student, "/student/<int:student_id>") if name: == *__ main" app.run(debug=True) The API is running on http: //127.0.0.1:5000/. Which of the following statements about this API's behavior is correct?
6406533954645.Source diagram or notation
6406533954646.Source diagram or notation
6406533954647.Source diagram or notation

Published solution

Let us trace each HTTP request against the `Student(Resource)` implementation (note that the first option `GET /student/2` was merged into the question stem during extraction, leaving 3 options A, B, and C): - **First statement in stem (`GET /student/2`)**: In `students`, key `2` has `{"name": "Kiran", "grade": "B+"}` (not `"B"`), so it is incorrect. - **Option A (`PUT /student/4`)**: Key `4` is **not** in `students` (`1, 2, 3`), so `put(self, 4)` returns `{"message": "Student not found"}, 404` (not 200). Thus Option A is **incorrect**. - **Option B (`GET /student/10`)**: Key `10` is not in `students`, so `get(self, 10)` returns `{"message": "Student not found"}` with **HTTP Status Code: 404**. (**Correct**) - **Option C (`PUT /student/1` with `{"grade": "A+"}`)**: Key `1` (`Arjun`) is in `students`. Its `"grade"` is updated from `"A"` to `"A+"`, and it returns `{"message": "Student record updated", "student": {"name": "Arjun", "grade": "A+"}}` with **HTTP Status Code: 200**. (**Correct**) **Answer: Options B and C.** A: **Incorrect:** Student 4 does not exist in `students`, so a `PUT` request to `/student/4` returns `{"message": "Student not found"}` with status code 404. B: **Correct:** Student 10 is not in `students`, so `GET /student/10` returns `{"message": "Student not found"}` with HTTP status code 404. C: **Correct:** Student 1 (`Arjun`) exists in `students`, so `PUT /student/1` updates his grade to `"A+"` and returns the updated record with HTTP status code 200.

Report a correction for Q62

Question 63 MSQ · 4.5 marks

Source diagram or notation
6406533954648.Source diagram or notation
6406533954649.Source diagram or notation
6406533954650.Source diagram or notation
6406533954651.Source diagram or notation
      **MLF** **Section Id :** 64065382674 **Section Number :** 5 **Section type :** Online **Mandatory or Optional :** Mandatory **Number of Questions :** 12 **Number of Questions to be attempted :** 12 **Section Marks :** 40 **Display Number Panel :** Yes **Section Negative Marks :** 0 **Group All Questions :** No **Enable Mark as Answered Mark for Review and** No **Clear Response :** **Section Maximum Duration :** 0 **Section Minimum Duration :** 0 **Section Time In :** Minutes **Maximum Instruction Time :** 0

Published solution

Let us examine what `url_for()` does in Flask: **1. `url_for()` vs `redirect()`:** - `url_for('function_name')` simply **returns the URL path string** associated with that view function (e.g., `'/if'` or `'/for'`). - It does **not** redirect the browser unless wrapped inside `redirect(url_for(...))`! **2. Tracing the Requests:** - When visiting `http://127.0.0.1:5000/choice/for`, `choice('for')` executes `return (url_for('for_loop'))`, which returns the plain string `"/for"` to the browser. - When visiting `http://127.0.0.1:5000/choice/if`, `choice('if')` executes `return url_for('ifelse')`, which returns the plain string `"/if"` to the browser. **Answer: Options C and D.** A: **Incorrect:** `choice('for')` returns `url_for('for_loop')` directly without calling `redirect()`, so it displays `/for` rather than `Welcome MAD II!`. B: **Incorrect:** `choice('if')` returns `url_for('ifelse')` directly without calling `redirect()`, so it displays `/if` rather than `Welcome MAD I!`. C: **Correct:** `url_for('for_loop')` returns the URL string `'/for'`, which is displayed directly by the browser. D: **Correct:** `url_for('ifelse')` returns the URL string `'/if'`, which is displayed directly by the browser.

Report a correction for Q63