You have a program that checks for a user's age to determine the price of a movie ticket. How would you structure the conditional statements to determine if a user gets a discount based on their age?

  • if age < 10 or age > 65:
  • if age == 10 or age == 65:
  • if age > 10 and age < 65:
  • if age >= 10 and age <= 65:
To determine if a user gets a discount based on age, you should use 'if' statements with logical OR operators. This way, you can identify both children under 10 and seniors above 65 who are eligible for a discount.

In the context of method overloading, what does the *args syntax in Python signify?

  • It represents default argument values
  • It represents keyword arguments in a function signature
  • It signifies that the function accepts a variable-length non-keyword argument list
  • It signifies that the function cannot accept any arguments
In Python, the *args syntax in a function signature indicates that the function accepts a variable-length non-keyword argument list. This allows you to pass a varying number of positional arguments to the function. It's commonly used in method overloading to handle multiple argument scenarios.

What happens if the base class method is private, and you try to override it in a derived class?

  • Compilation error
  • The base class method is called
  • The derived class method is overridden
  • The derived class method is private
If the base class method is private, it cannot be overridden in the derived class. Attempting to do so will result in a compilation error, as private methods are not accessible outside the class.

Which of the following decorators is used to define a setter method for a property in Python?

  • @getter
  • @property
  • @setter
  • @setter and @getter
The @property decorator is used to define a getter method for a property. To define a setter, you would use @.setter.

Which built-in function in Python can be used to get the data type of an object?

  • dtype()
  • type()
  • typeof()
  • typeofobject()
The type() function is used to determine the data type of an object in Python. It returns a type object, which represents the data type of the given object.

If you have a function named fun inside a module named mod, how can you import it directly?

  • from mod import fun
  • fun(mod)
  • import fun from mod
  • include mod.fun
To import a specific function from a module, you use the syntax from mod import fun. This allows you to use fun directly in your code.

How can you pass dynamic data from a Python back-end to a JavaScript variable in the front-end?

  • Include Python variables directly in JavaScript code.
  • Use AJAX requests to fetch data from the Python back-end.
  • Use HTTP cookies to store Python data for JavaScript to access.
  • Use WebSockets to establish a real-time connection.
To pass dynamic data from a Python back-end to a JavaScript variable, you typically use AJAX (Asynchronous JavaScript and XML) requests. This allows you to make asynchronous requests to the back-end, retrieve data, and update JavaScript variables without refreshing the entire page.

How can you perform element-wise multiplication of two NumPy arrays?

  • array1 * array2
  • array1.multiply(array2)
  • np.multiply(array1, array2)
  • np.multiply_elements(array1, array2)
To perform element-wise multiplication of two NumPy arrays, you can simply use the * operator between the two arrays. NumPy overloads arithmetic operations to work element-wise.

How can you prevent overfitting in a deep learning model developed with TensorFlow or PyTorch?

  • Decrease the learning rate
  • Increase the model complexity
  • Use a smaller training dataset
  • Use dropout layers
To prevent overfitting, using dropout layers is a common technique. Dropout layers randomly deactivate a fraction of neurons during training, which helps the model generalize better to new data.

How can you profile a Python script to analyze the time spent in each function call?

  • Use the cProfile module to profile the script, which provides detailed information about the time spent in each function call.
  • Use the inspect module to analyze the source code of the script.
  • Use the timeit module to measure the execution time of the entire script.
  • Use the trace module to trace the execution of the script line by line.
Profiling a Python script to analyze function call times involves using the cProfile module, which provides detailed statistics on function calls, including time spent in each function.