There are many issues wrong with your code.
First the, code is not properly formatted, the indentation does not follow the level of code. All code should be indented from from function declaration.
Second, Input returns a string and not a integer so you can't compare it to a range of integers like you did here,Also range does not include second number so you have to change it to 7000:
if ID in range(1000,6999):
You can you the map function to return the individual digits.
DIGITS = []
# append each digit to list
for digit in map(int, ID):
DIGITS.append(digit)
Finally, you can check the sum of the digits and see if they are divisible by seven
# Check if sum of digits is divisible by seven
if sum(DIGITS) % 7 == 0:
print(True)
# Not divisible by 7
else:
print(False)
Here is the complete code:
def is_valid():
# Obtain ID Number
ID = input("Enter ID number:")
if int(ID) in range(1000, 7000):
# List for individual digit in input
DIGITS = []
# append each digit to list
for digit in map(int, ID):
DIGITS.append(digit)
# Check if sum of digits is divisible by seven
if sum(DIGITS) % 7 == 0:
print(True)
# Not divisible by 7
else:
print(False)
# Not between 1000 inclusive and 7000 exclusive
else:
print(False)
is_valid()