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 · 3.0 marks
A client sends a signal to a satellite 36,000 km above Earth. Speed of electromagnetic waves in
vacuum = 3 × 10\(^{8}\) m/s. Compute RTT for client ↔ satellite.
6406535937174.
0.24 s
6406535937175.
0.36 s
6406535937176.
0.48 s
6406535937177.
0.72 s
Published solution
**1. Convert Distance to Meters and Calculate One-Way Propagation Delay:**
- Distance to satellite: \( d = 36,000 \text{ km} = 3.6 \times 10^7 \text{ m} \).
- Speed of electromagnetic waves: \( c = 3 \times 10^8 \text{ m/s} \).
- One-way propagation time:
\[ t_{\text{one-way}} = \frac{d}{c} = \frac{3.6 \times 10^7 \text{ m}}{3 \times 10^8 \text{ m/s}} = 0.12 \text{ s} \]
**2. Calculate Round-Trip Time (RTT):**
- Round-Trip Time (client \( \to \) satellite \( \to \) client) is twice the one-way propagation time:
\[ \text{RTT} = 2 \times 0.12 \text{ s} = 0.24 \text{ s} \]
**Answer: 0.24 s (Option A).**
A: **Correct:** One-way delay is \( \frac{3.6 \times 10^7}{3 \times 10^8} = 0.12 \text{ s} \), so \( \text{RTT} = 2 \times 0.12 = 0.24 \text{ s} \).
B: **Incorrect:** 0.36 s is three times the one-way propagation delay.
C: **Incorrect:** 0.48 s is four times the one-way propagation delay.
D: **Incorrect:** 0.72 s is six times the one-way propagation delay.
What will be the output if you visit **127.0.0.1:5000/hello** ?
6406535937178.
"Hello World!"
6406535937179.
"Home"
6406535937180.
404 Not Found
6406535937181.
"Hello /hello"
Published solution
**1. Trace Route Matching in the Flask Application:**
- In the code, the view function `greet()` is decorated with two static routes:
`@app.route('/hello')`
`@app.route('/hi')`
- Meanwhile, `greet_name(name)` is decorated with `@app.route('/hello/<name>')`, which requires a second path segment `<name>` after `/hello/`.
- Therefore, visiting `127.0.0.1:5000/hello` matches `@app.route('/hello')` on `greet()` and returns **`"Hello World!"`**.
**Answer: "Hello World!" (Option A).**
A: **Correct:** `/hello` matches the `@app.route('/hello')` decorator on `greet()`, returning `"Hello World!"`.
B: **Incorrect:** `"Home"` is returned only when visiting the root path `/`.
C: **Incorrect:** `/hello` is a registered route, so it does not return 404.
D: **Incorrect:** `greet_name(name)` only matches `/hello/<name>` when a `<name>` segment is provided after `/hello/`.
If a POST request is sent to **127.0.0.1:5000/data/5**, what will be the output on the browser?
6406535937182.
"GET Data"
6406535937183.
"Data ID: 5"
6406535937184.
405 Method Not Allowed
6406535937185.
404 Not Found
Published solution
**1. Check Allowed HTTP Methods on Flask Routes:**
- In Flask, `@app.route('/data/<int:id>')` without an explicit `methods=[...]` argument only allows **`GET`** (along with `HEAD` and `OPTIONS`) requests by default.
- When a **`POST`** request is sent to `127.0.0.1:5000/data/5`, the URL path matches `/data/<int:id>`, but the HTTP method `POST` is not permitted for that endpoint.
- Therefore, Flask responds with **`405 Method Not Allowed`**.
**Answer: 405 Method Not Allowed (Option C).**
A: **Incorrect:** `/data/5` matches `/data/<int:id>`, not `/data`, and uses `POST` rather than `GET`.
B: **Incorrect:** `"Data ID: 5"` is returned only for a `GET` request to `/data/5`, not a `POST` request.
C: **Correct:** Because the route `/data/<int:id>` exists but only accepts `GET` by default, sending a `POST` request triggers `405 Method Not Allowed`.
D: **Incorrect:** `404 Not Found` occurs when no URL rule matches the path at all, whereas `/data/5` matches the route path.
What will be the output on the browser, if you visit **127.0.0.1:5000/post/23**?
6406535937186.
Post ID: 23
6406535937187.
"All posts"
6406535937188.
404 Not Found
6406535937189.
Flask throws AssertionError
Published solution
**1. Trace Multiple Route Decorators with Different Converters:**
- The function `post(id)` is decorated with both:
`@app.route('/post/<int:id>')`
`@app.route('/post/<string:id>')`
- Both decorators bind to the same view function `post(id)`.
- When visiting `127.0.0.1:5000/post/23`, the path matches `/post/<int:id>` with `id = 23` and returns **`Post ID: 23`**.
**Answer: Post ID: 23 (Option A).**
A: **Correct:** `/post/23` matches `post(id)` with `id=23` and renders `Post ID: 23`.
B: **Incorrect:** `"All posts"` is only returned for `/post` without a trailing ID.
C: **Incorrect:** `/post/23` matches the registered route `/post/<int:id>`.
D: **Incorrect:** Stacking multiple `@app.route` decorators on the same view function is completely valid in Flask.
**1. Understand `app.run(port=0000)` (`port=0`) in Flask / OS Networking:**
- In Python/OS socket programming, passing `port=0` (or `0000`) to `app.run(port=0)` tells the operating system kernel to dynamically assign **any available ephemeral (random free) port** (such as `38491` or `54321`), not port `5000` and not literal port `0`.
- Also, Flask runs over `http://` (not `https://`) by default.
- Therefore, none of `https://127.0.0.1:5000/`, `http://localhost:0000/`, or `http://0.0.0.0:5000/` is the URL; the correct choice is **`None of these`**.
**Answer: None of these (Option D).**
A: **Incorrect:** Flask uses `http` by default (not `https`), and `port=0` does not bind to port 5000.
B: **Incorrect:** Port 0 is a reserved OS wildcard that tells the kernel to pick a random free port; you cannot browse to `:0000`.
C: **Incorrect:** Because `port=0000` is specified, the server binds to a dynamically assigned OS port rather than port 5000.
D: **Correct:** Specifying `port=0` makes the OS assign a random available ephemeral port over HTTP, so none of the listed URLs is correct.
Match the **Flask-RESTful components** with their correct **description/role:**
6406535937194.
1 → A, 2 → B, 3 → C, 4 → D
6406535937195.
1 → E, 2 → C, 3 → B, 4 → A
6406535937196.
1 → B, 2 → C, 3 → A, 4 → D
6406535937197.
1 → B, 2 → C, 3 → A, 4 → E
Published solution
**1. Match Each Flask-RESTful Component with Its Role:**
- **1. `Resource` \( \to \) B:** Represents an endpoint in the API and defines HTTP methods like `get()`, `post()`, `put()`, `delete()`.
- **2. `Api` \( \to \) C:** Binds all resources to the Flask app and manages routing.
- **3. `reqparse` \( \to \) A:** Used to parse and validate incoming request data/arguments.
- **4. `marshal_with / fields` \( \to \) E:** Used to serialize Python objects (such as SQLAlchemy models) into JSON-compatible dicts for API responses.
**Answer: 1 → B, 2 → C, 3 → A, 4 → E (Option D).**
A: **Incorrect:** `Resource` defines API endpoints (B), not request parsing (A).
B: **Incorrect:** `Resource` maps to B and `reqparse` maps to A.
C: **Incorrect:** `marshal_with / fields` serializes Python objects into JSON for API responses (E), not JSON into a Python list (D).
D: **Correct:** Matches `Resource` → B, `Api` → C, `reqparse` → A, and `marshal_with / fields` → E.
What happens if you don’t return a proper dictionary/JSON in Flask-Restful API methods?
6406535937198.
Returns None
6406535937199.
Raises an error that the value is not serializable
6406535937200.
Converts into plain text
6406535937201.
Automatically converts into JSON format
Published solution
**1. Behavior of Flask-RESTful When Returning a Non-Serializable Object:**
- Flask-RESTful automatically serializes the return value of a `Resource` method to JSON using `json.dumps()`.
- If a method returns an arbitrary Python object (such as a raw SQLAlchemy model instance or custom class) instead of a JSON-serializable dictionary/list/primitive, Python's JSON encoder raises a **`TypeError: Object of type ... is not JSON serializable`**.
**Answer: Raises an error that the value is not serializable (Option B).**
A: **Incorrect:** It does not silently return `None`; it throws a `TypeError` during JSON serialization.
B: **Correct:** Returning a non-JSON-serializable object from a Flask-RESTful resource method raises a `TypeError` stating the object is not JSON serializable.
C: **Incorrect:** Flask-RESTful formats responses as `application/json` by default, not plain text.
D: **Incorrect:** Custom Python objects cannot be automatically converted to JSON without `marshal_with` or converting them to a `dict`.
**1. Match Each Flask-SQLAlchemy Construct with Its Description:**
- **`i) db.Model` \( \to \) `d)`:** Base class for ORM models.
- **`ii) db.Column(db.Integer, primary_key=True)` \( \to \) `c)`:** Defines a column with unique row identification (primary key).
- **`iii) db.relationship()` \( \to \) `b)`:** Defines one-to-many or many-to-many ORM mapping between models.
- **`iv) db.create_all()` \( \to \) `a)`:** Creates missing database tables from defined ORM models.
**Answer: i - d, ii - c, iii - b, iv - a (Option D).**
A: **Incorrect:** `db.Model` is the base class for ORM models (`d`), not `c`.
B: **Incorrect:** `db.relationship()` defines ORM relationship mappings (`b`), whereas `db.create_all()` creates tables (`a`).
C: **Incorrect:** `db.Model` is `d` and `db.relationship()` is `b`.
D: **Correct:** Matches `i - d`, `ii - c`, `iii - b`, and `iv - a`.
**1. Understand `default=3` in `db.Column(db.Integer, default=3)`:**
- In SQLAlchemy, specifying `default=3` on `credits = db.Column(db.Integer, default=3)` sets a default value for the column upon `INSERT`.
- If a new `Course` record is created without providing a value for `credits`, SQLAlchemy automatically assigns **`3`** to `credits`. If a value is provided (e.g., `credits=4`), that provided value is stored.
**Answer: If the value is not provided, it takes 3 (Option B).**
A: **Incorrect:** Only integer primary key columns (or columns with `autoincrement=True`) auto-increment.
B: **Correct:** `default=3` assigns the value `3` whenever `credits` is omitted when inserting a new row.
C: **Incorrect:** `default=3` sets a static default value of `3`, not an auto-incrementing sequence.
D: **Incorrect:** Any integer value can be stored in `credits` when explicitly provided.
**1. Query String Types and Flask View Return Types:**
- `request.args.get('x')` and `request.args.get('y')` return **strings** (e.g., `'3'` and `'5'`).
- To compute their integer sum (rather than string concatenation `'35'`), we must convert each to an integer first: `int(argv1) + int(argv2)`.
- Furthermore, in Flask (especially older versions / standard view rules), a view function cannot return a raw `int` directly—it must return a `str`, `Response`, `dict`, `list`, or tuple, so we convert the sum back to a string: **`return str(int(argv1)+int(argv2))`**.
**Answer: return str(int(argv1)+int(argv2)) (Option A).**
A: **Correct:** Converts both query parameters from `str` to `int`, adds them numerically, and converts the result back to a `str` for the HTTP response.
B: **Incorrect:** Returning a raw `int` from a Flask view function raises a `TypeError: The view function did not return a valid response`.
C: **Incorrect:** Since `argv1` and `argv2` are strings, `argv1 + argv2` performs string concatenation (e.g., `'2' + '3' = '23'`) instead of addition.
D: **Incorrect:** `argv1 + argv2` concatenates the strings first before converting to `int`.
**1. Trace `sys.argv[1:]` in `main.py` Under Different Command-Line Invocations:**
- **Case 1 (`python main.py 1 2 3`):**
- `sys.argv` is `['main.py', '1', '2', '3']`, so `sys.argv[1:]` is `['1', '2', '3']`.
- `[int(x) for x in sys.argv[1:]]` produces `[1, 2, 3]`, whose product is \( 1 \times 2 \times 3 = 6 \).
- Visiting `http://127.0.0.1:5000` renders **`Product is: 6`** (**Option A is correct**, Option E is false).
- **Case 2 (`python main.py '1 2 3'`):**
- Because `'1 2 3'` is quoted as a single argument, `sys.argv[1:]` is `['1 2 3']`.
- Inside `do_product()`, `int('1 2 3')` fails because `'1 2 3'` contains spaces, raising a **`ValueError`** (`invalid literal for int() with base 10: '1 2 3'`) (**Option C is correct**, Options B and D are false).
**Answer: Options A and C.**
A: **Correct:** Passing `1 2 3` as separate command-line arguments gives `nums = [1, 2, 3]` and renders `Product is: 6`.
B: **Incorrect:** Passing `'1 2 3'` as a single quoted string causes `int('1 2 3')` to raise a `ValueError`.
C: **Correct:** `int('1 2 3')` cannot parse space-separated numbers in a single string and raises a `ValueError`.
D: **Incorrect:** Since `len(sys.argv) == 2 > 1`, it enters the `if` block and raises `ValueError` rather than returning `None`.
E: **Incorrect:** `nums` contains integers `[1, 2, 3]` multiplied together (`6`), not string concatenation (`123`).
Consider the URL:
**https://example.com:8080/index.html?user=admin#section2**
Which of the following is/are True?
6406535937219.
https is the protocol.
6406535937220.
8080 is the default port of HTTPS.
6406535937221.
index.html is the html file which got rendered.
6406535937222.
user=admin is part of the query string.
6406535937223.
#section2 is sent to the server as part of the request.
Published solution
**1. Dissect the URL `https://example.com:8080/index.html?user=admin#section2`:**
- **`https` (Scheme/Protocol):** Specifies the protocol used (**Option A is true**).
- **`:8080` (Port):** Explicit port number. Note that the **default port of HTTPS is `443`**, not `8080` (**Option B is false**).
- **`/index.html` (Path):** Path to the HTML resource rendered (**Option C is true**).
- **`?user=admin` (Query String):** Key-value query parameter following `?` (**Option D is true**).
- **`#section2` (Fragment/Hash):** Client-side anchor processed exclusively by the browser; URL fragments are **never sent to the server** in HTTP requests (**Option E is false**).
**Answer: Options A, C, and D.**
A: **Correct:** `https` is the scheme/protocol of the URL.
B: **Incorrect:** The default port for HTTPS is 443; 8080 is a custom non-default port specified in this URL.
C: **Correct:** `/index.html` is the requested HTML file path.
D: **Correct:** `user=admin` after `?` is the query string parameter.
E: **Incorrect:** The fragment identifier `#section2` is handled purely client-side by the browser and is never sent to the server.
Match the **JavaScript event binding method** with its correct **description:**
6406535937224.
1 → A, 2 → B, 3 → C, 4 → E
6406535937225.
1 → B, 2 → A, 3 → C, 4 → E
6406535937226.
1 → B, 2 → A, 3 → C, 4 → D
6406535937227.
1 → A, 2 → B, 3 → D, 4 → C
Published solution
**1. Match Each JavaScript Method/Binding with Its Description:**
- **1. `Inline onclick` \( \to \) B:** Quick for small demos, mixes HTML and logic.
- **2. `addEventListener` \( \to \) A:** Adds event listener from JS code, keeps HTML clean.
- **3. `prompt()` \( \to \) C:** Displays a popup asking user input.
- **4. `console.table()` \( \to \) E:** Logs array/object data in a tabular format in console.
**Answer: 1 → B, 2 → A, 3 → C, 4 → E (Option B).**
A: **Incorrect:** Swaps `Inline onclick` (which mixes HTML and JS, B) and `addEventListener` (which keeps HTML clean, A).
B: **Correct:** Matches `1 → B`, `2 → A`, `3 → C`, and `4 → E`.
C: **Incorrect:** `console.table()` logs data in a tabular format (E), whereas `console.log()` logs in standard line format (D).
D: **Incorrect:** Incorrect matches for 1, 2, 3, and 4.
**1. Evaluate Each Statement About JavaScript Output Methods:**
- **Option A (`alert()`):** Displays a modal popup message box to the user (**True**).
- **Option B (`console.log()`):** Writes debugging/log output to the browser's developer console (**True**).
- **Option C (`document.write()`):** If called after the HTML document has finished loading, `document.write()` **overwrites the entire existing document**, rather than safely appending to the DOM (**False**).
- **Option D (`innerHTML`):** Reads or updates the HTML content inside a DOM element (**True**).
**Answer: Options A, B, and D.**
A: **Correct:** `alert()` shows a modal dialog box with a message to the user.
B: **Correct:** `console.log()` prints messages to the browser's developer console.
C: **Incorrect:** Calling `document.write()` on a loaded page overwrites the entire document rather than appending without overwriting.
D: **Correct:** Setting `element.innerHTML` dynamically updates the HTML content inside that element.
You are building a Flask-RESTful API with the following code:
Which of the following statements is/are true?(Select all that apply)
6406535937232.6406535937233.6406535937234.
The Api class automatically handles URL routing for all resources
6406535937235.
This API will return HTML content when accessed via a browser
Published solution
**1. Analyze the Flask-RESTful `Hello(Resource)` Code:**
- **Option A:** In `def get(self, message="No Data Found"): return {"message": "Hello, World!"}`, the method ignores the `message` parameter and always returns `{"message": "Hello, World!"}` (**Option A is false**).
- **Option B:** Sending a `POST` request with JSON `{"name": "Alice"}` parses `data = request.get_json()` and returns `{"received": {"name": "Alice"}}` with status `201` (**Option B is true**).
- **Option C:** The `Api` class (`api.add_resource(...)`) automatically manages URL routing and HTTP method dispatching for registered resources (**Option C is true**).
- **Option D:** Flask-RESTful serializes responses as **JSON** (`application/json`), not HTML, even when accessed via a browser (**Option D is false**).
**Answer: Options B and C.**
A: **Incorrect:** `get()` returns the hardcoded dictionary `{"message": "Hello, World!"}`, not `{"message": "No Data Found"}`.
B: **Correct:** `post()` reads the JSON body via `request.get_json()` and returns `{"received": {"name": "Alice"}}`.
C: **Correct:** `Api` handles registering and routing URLs to `Resource` classes via `api.add_resource`.
D: **Incorrect:** Flask-RESTful returns JSON responses (`application/json`) by default, not HTML.
Which of the following SQL queries will return the **names of students who are 20 years old and**
**have grade 'A'**?
6406535937236.
SELECT name FROM students WHERE age = 20 AND grade = 'A';
6406535937237.
SELECT * FROM students WHERE age = 20 OR grade = 'A';
6406535937238.
SELECT name FROM students WHERE students.age = 20 AND grade = 'A';
6406535937239.
SELECT name FROM students WHERE student.grade = 'A' OR student.age = 20;
**MLF**
**Section Id :** 640653122504
**Section Number :** 5
**Section type :** Online
**Mandatory or Optional :** Mandatory
**Number of Questions :** 10
**Number of Questions to be attempted :** 10
**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
**1. Evaluate Each SQL Query:**
- We want only the **`name`** column (`SELECT name`) of rows from table **`students`** where **both** `age = 20` **and** `grade = 'A'` (`WHERE age = 20 AND grade = 'A'`).
- **Option A (`SELECT name FROM students WHERE age = 20 AND grade = 'A';`):** Valid SQL returning the names of students aged 20 with grade `'A'`. (**Correct**)
- **Option B (`SELECT * ... OR ...`):** Selects all columns (`*`) instead of `name`, and uses `OR` instead of `AND`. (**Incorrect**)
- **Option C (`SELECT name FROM students WHERE students.age = 20 AND grade = 'A';`):** Prefixing the column name with the table name (`students.age`) is completely valid SQL and returns the exact same result as Option A. (**Correct**)
- **Option D (`... WHERE student.grade = 'A' OR ...`):** Uses the wrong table name `student` (instead of `students`) and uses `OR` instead of `AND`. (**Incorrect**)
**Answer: Options A and C.**
A: **Correct:** Selects the `name` column from `students` filtering for both `age = 20` and `grade = 'A'`.
B: **Incorrect:** Uses `SELECT *` (all columns) and `OR` instead of `AND`.
C: **Correct:** Qualifying `students.age` with the table name `students` is valid SQL and filters for `age = 20 AND grade = 'A'`.
D: **Incorrect:** Uses `OR` instead of `AND`, and references an invalid table alias `student` instead of `students`.