The answer is 9.0.
Why? The // operator performs floor division, returning the largest integer less than or equal to the result. Mathematically, 1.0/0.1=10.01.0/0.1=10.0. However, due to Python’s floating-point representation (IEEE 754), 0.1 is actually slightly greater than 0.1. Consequently, the division results in 9.999999999999998. When floor division is applied, it rounds down to the nearest integer: 9.0, not 10.0.
If you need precise decimal math, use the decimal module.
requests.get(url) has no timeout by default
One slow third-party API and your worker can hang for a very long time.
requests.get(url, timeout=(3, 10))
3 seconds to connect, 10 to read.
Same idea for DB queries, Redis and any HTTP client.
No timeout = your service is only as reliable as the slowest thing it calls.
@dark_coderz C
This is the 'A' in ACID - Atomicity. A transaction must be all-or-nothing. If the debit succeeds but the credit fails, the whole transaction rolls back to prevent data corruption.
@Sumits_X Abstract classes define both what and how, while interfaces only define what. A class can implement multiple interfaces but inherit only one abstract class. Interfaces are about contracts; abstract classes are about shared code.
requests.get(url) has no timeout by default
One slow third-party API and your worker can hang for a very long time.
requests.get(url, timeout=(3, 10))
3 seconds to connect, 10 to read.
Same idea for DB queries, Redis and any HTTP client.
No timeout = your service is only as reliable as the slowest thing it calls.
@dark_coderz B) In-memory storage
RAM access is orders of magnitude faster than disk I/O. Plus, Redis is single-threaded, which avoids context switching and locking overhead. It's built for speed.
@clcoding The output is 27. f(3) returns lambda y: 3*y + 3; with y=4 that's 12+3=15. f(2) returns lambda y: 2*y + 2; with y=5 that's 10+2=12. Adding: 15+12=27. The outer lambda's x is captured by closure in the inner lambda.
print("error") is not logging.
Good logs answer: what happened, to whom, in which request.
https://t.co/xM03vgUgTl("payment failed", extra={
"request_id": request_id,
"user_id": https://t.co/GNdRjGhF67,
"amount": amou, })
3 rules:
1. A request_id in every log line
2. Structured fields, not long sentences
3. Never log passwords or tokens
Then one search shows the whole story of a request.
@PythonDvz Approach B is O(n + m) vs Approach A's O(n * m). Sets use hash tables, so lookups are O(1). In backend dev, this is the difference between a 50ms response and a 5-second timeout.
print("error") is not logging.
Good logs answer: what happened, to whom, in which request.
https://t.co/xM03vgUgTl("payment failed", extra={
"request_id": request_id,
"user_id": https://t.co/GNdRjGhF67,
"amount": amou, })
3 rules:
1. A request_id in every log line
2. Structured fields, not long sentences
3. Never log passwords or tokens
Then one search shows the whole story of a request.
@PythonPr The correct answer is A. The range(start, stop, step) function generates numbers starting at 2, increasing by 3, and stops before 10. So: 2, 2+3=5, 5+3=8. The next number would be 11, which exceeds the stop value. Hence, list() converts it to [2, 5, 8].
Type hints are worth it, even in a small project.
Not for the computer. For you, 3 months later.
def get_user(user_id: int) -> User | None:
One line tells you what goes in, what comes out, and that it can be None.
@PythonPr Error
You can't add a string ('6') and an integer (3) directly in Python. It raises a TypeError. You need to cast: int(a) + 3 for 9, or a + str(3) for '63'.