Bird
0
0

Identify the error in this code snippet:

medium📝 Debug Q14 of 15
SciPy - Integration with Scientific Ecosystem

Identify the error in this code snippet:

from scipy.io import savemat
my_data = {'x': [1, 2, 3]}
savemat(my_data, 'data.mat')
ADictionary keys must be strings
BList values cannot be saved in .mat files
CArguments to savemat are in wrong order
DMissing import statement
Step-by-Step Solution
Solution:
  1. Step 1: Check savemat argument order

    savemat expects filename first, then dictionary.
  2. Step 2: Identify argument swap

    Code passes dictionary first, filename second, which is incorrect.
  3. Final Answer:

    Arguments to savemat are in wrong order -> Option C
  4. Quick Check:

    savemat(filename, dict) order matters [OK]
Quick Trick: Filename is first argument in savemat [OK]
Common Mistakes:
  • Swapping filename and data arguments
  • Assuming lists can't be saved
  • Forgetting to import savemat

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SciPy Quizzes