A ____ algorithm guarantees to run in the same time (or space) for any input of the same size.

  • Deterministic
  • In-Place
  • Non-Deterministic
  • Stable
A Deterministic algorithm guarantees to run in the same time (or space) for any input of the same size. It is predictable and has consistent performance.

How can you secure sensitive information, like API keys, in a Flask or Django application?

  • Embed them directly in the code
  • Encrypt them using a reversible algorithm
  • Publish them in the application's source code
  • Store them in environment variables
Sensitive information, like API keys, should be stored in environment variables for security. Embedding them directly in the code or publishing them in the source code can expose them, and reversible encryption is not recommended.

To iterate over a list and its indices simultaneously, you can use the ____ function.

  • enumerate
  • for
  • index
  • range

The enumerate function is used in Python to iterate over a list and its corresponding indices. It returns pairs of index-value tuples, making it convenient for tasks that require both the index and the value during iteration.

The ____ keyword is used to create a block of code that can handle exceptions in Python.

  • catch
  • finally
  • throw
  • try

The try keyword is used in Python to create a block of code that might raise exceptions. It is followed by an associated except block that catches and handles those exceptions. This combination allows for controlled error handling in Python.

How can you create an else block that executes after a for loop, but only if the loop completed normally (i.e., did not encounter a break statement)?

  • Place the code after the "for" loop without any specific block.
  • Use the "except" block
  • Use the "finally" block
  • You cannot create an "else" block for this purpose in Python.

In Python, you can create an "else" block that executes after a for loop but only if the loop completed normally (without encountering a "break" statement). To do this, you can use the "else" block immediately following the "for" loop. If the loop completes normally, the "else" block will execute.

What is the output of the following Python code snippet: print(all([True, False, True]))?

  • Error
  • FALSE
  • SyntaxError
  • TRUE

The all() function in Python returns True if all elements in the iterable are True. In this case, it returns False because one of the elements (False) is not True.

How can you create a custom exception class in Python?

  • class MyException(Exception):
  • define MyException as a function
  • import customexception
  • MyException extends Throwable

To create a custom exception class in Python, you should define a new class that inherits from the built-in Exception class (or one of its subclasses). This allows you to raise and catch instances of your custom exception when necessary.

How would you create a try block that catches both ValueError and TypeError exceptions?

  • try: catch ValueError, TypeError:
  • try: except (ValueError, TypeError):
  • try: except Exception as e:
  • try: except ValueError, TypeError:

To catch multiple exceptions like ValueError and TypeError in Python, you should use the except (ValueError, TypeError): syntax. This allows you to handle multiple exception types in a single except block.

Which Python built-in function can be used to iterate over a sequence while also obtaining the index of the current item?

  • enumerate()
  • for_each()
  • index()
  • iterate()

The enumerate() function in Python is used to iterate over a sequence (like a list or tuple) while also obtaining the index of the current item. It returns pairs of index and value, making it helpful for certain looping scenarios.

How can you exit a loop prematurely in Python?

  • break
  • exit
  • stop
  • terminate

In Python, you can exit a loop prematurely using the break statement. When break is encountered within a loop, it immediately terminates the loop and continues with the next code after the loop.

What keyword is used to catch exceptions in Python?

  • catch
  • except
  • throw
  • try

In Python, you use the "except" keyword to catch exceptions. Exceptions are used to handle errors and unexpected situations in your code. When an exception occurs, the code within the "except" block is executed.

How do you create a loop that iterates as long as a specific condition is true?

  • for
  • repeat
  • until
  • while

In Python, you use the "while" keyword to create a loop that continues to iterate as long as a specific condition is true. The condition is evaluated before each iteration.