0

What does the following error mean?

Unindent does not match previous indent [6,3] Can't find the error on "Expected ")" Pylance [16,9]. Import "Numpy" could not be resolved

Here is part of the code producing the error

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
Titan
  • 1
  • 1
  • 2
  • 2
    It means something is improperly formatted in your code, possibly with incorrect syntax as well. If you post the code you are trying to run then you can get specific help. As it is, it means you have an error, and there isn't much else we can say. – h0r53 Jul 13 '21 at 19:52
  • Can you share your sample code to check where the indentation issue occurs? Also sometimes tabs cause this issue in Python. For indenting try using 4 spaces instead of tabs. This should work – Rajalakshmi Jul 13 '21 at 19:53
  • 1
    Maybe add a `)` to the end of line 15 :o? – MDR Jul 13 '21 at 19:56
  • Sorry, I'm new to this. I added the link of my image "enter image description here". – Titan Jul 13 '21 at 19:56
  • Sorry but the image is not visible to me. – Rajalakshmi Jul 13 '21 at 19:57
  • 1
    Your immediate problem is a missing closing paren `)` on line 15. But the next line has a syntax error so fixing line 15 won't get you far. And line 17 is indented with respect to the line above it and should not be because there is no need for indentation there. – BoarGules Jul 13 '21 at 20:08
  • Note, simple syntax errors are considered as off-topic. [help] – OneCricketeer Jul 13 '21 at 20:23

2 Answers2

1

"Pylance reportUndefinedVariable" had solved by editing the last two lines in settings as follows.

settings >> code actions not saved >> edit in settings.json

"editor.codeActionsOnSave": {},
"source.addMissingImports": {}
Pawara Siriwardhane
  • 1,873
  • 10
  • 26
  • 38
Bibin
  • 199
  • 2
  • 10
0

Based on your image,

  1. You need a ) at the end of line 15. You are properly closing format(...) but you never close input(...).

  2. Whatever is on line 16 needs to be commented out. You can comment out a line in Python with the # character as the leftmost character.

  3. Lines 17 and on are indented too far. The quick way to "un-indent" them is to highlight the lines, hold shift, and press tab. The body of your function definitions show_score and start_game are also indented too far. Use a single indent.

  4. Based on your message you are improperly importing numpy somewhere in your code. You should ensure you spell it correctly, such as import numpy or import numpy as np (casing matters). If you have not yet installed the numpy package you can do so with pip install numpy or conda install numpy depending on your Python package manager.

As a rule of thumb you should be very careful with indentation in Python, as it is part of the syntax. You are using inconsistent indentation throughout your entire file. Only indent following definitions, conditions such as if or else, after try and catch, and for the body of loops such as for and while. Other cases also exist for indentation. If you are familiar with other languages such as C, C++, Java, C#, and many more, then you may be used to using {} for scoping. In Python scope is indicated by indentation, which is why it's important to be careful.

If you update your question to actually provide your code as text and not a screenshot, we can help you fix your indentation issues.

h0r53
  • 3,034
  • 2
  • 16
  • 25