-1

I'm using python with the 'Spyder IDE'

Wrote this code a week ago and when I open the file after a week, the code is giving me an indentation error. The code is meant to take a six-digit number inputted from the user and put it through a few tests using if/else and match statements.

import numpy as np

code = input('Please enter a code to break: ')
code = np.array(list(code),dtype=int)
Sum = sum(code[:3])
Sum2 = sum(code[-3:])

# Rule 1, checks whether the user inputted code is six digits long.
#
if len(code) != 6:                                                              #<-- Line 35
    print("Decoy Message: Not a six-digit number")                               
    
# Rule 2, performs requested equation and tests whether its even or odd.
#
else : 
    if (Sum-Sum2) % 2 != 0:
        print("Decoy Message: Sum is odd")

The code doesn't ask for input from the user in the console window, but instead immediately gives an indentation error: IndentationError: expected an indented block after 'if' statement on line 35

Does anyone know what might be the cause? I haven't downloaded anything new since I wrote the code only a week ago.

Dylan C-W
  • 1
  • 2
  • Cannot reproduce — your code as posted works. Your code is almost certainly different than what you posted. Make sure you post an [example] (with emphasis on "reproducible" — i.e. if you paste the code back into your environment, it shows the same behaviour). – Amadan Oct 21 '22 at 04:55
  • I don't see an issue in the code. I tried executing it and it worked well. So just check it once again. – MOHAN KRISHNA LANDA Oct 21 '22 at 04:57

2 Answers2

1

It works fine for me. My guess is maybe there's a hidden space or something there? I'd just delete those two lines (35-36) and re-type them and see if you get the same error.

Quoc Tran
  • 45
  • 5
1

You probably have a mix of tabs and spaces. Erase each indent and replace them with four spaces. The standard shown in the style guide is to use spaces Tabs or Spaces.

roberthayek
  • 167
  • 2
  • 10