My Error
Python throws a syntax error pointed at the last "e" of "else:", preceded by an if statement and inside a while loop.
My Objective
Test if certain parameters are true, if true then go to the beginning of the loop and if not true then perform certain statements and increment a value.
My Source Code
from random import randint
def returnDigRoot(num):
digs = []
while len(str(num)) != 1:
num = str(num)
for each in num:
digs.append(each)
num = int(num)
digs = [int(i) for i in digs]
num = sum(digs)
return(num)
def rnum():
return(randint(1,99999))
ran_nums = []
sols = []
it = 1
The problem area is here
while it <= 3:
print("Generating numbers")
current = randint(1,99999)
print("randomly intializing the 'current' int value")
print("testing if the digital root is greater than 6")
if returnDigRoot(current) > 6:
print("going back to start of loop")
continue
print("testing if it isnt")
else:
ran_nums.append(current)
print("append 'current' to ran_nums")
sols.append(returnDigRoot(current))
print("appending its digital root to sols")
it += 1
print("incrementing the iterator variable")
My Research
I looked at many questions on StackOverflow and other sites and could not find a solution to my problem; most problems people had with else statements were related to tabbing errors, preceding errors (which I checked for), no preceding if statement, or multiple else statements.
Thanks in advance for any help.