I've been trying to understand this for a while now and I don't get why the true while loop doesn't exit when the check() function returns False value and asks input(i.e "enter input")again and again but it exits when else statement of func() function returns False value. No matter what,as far as I know, the while loop should stop or exit when the value returned is false, but that isn't the case here. I don't intend to modify the code but would just like to understand the concept behind this. please help me. Thanks! in advance.
def check(num):
if(num%2==0):
return True
else:
return False
def func():
temp=[str(i) for i in range(1,51)]
while True:
c=input("enter input: ")
if c in temp:
c=int(c)
if check(c):
print(c)
break
else:
print("input invalid, enter only digits from 1 to 50")
return False
returnstatement, or other way to end the loop, when theif c in tempcondition passes but theif check(c)one doesn't. Try following the logic yourself, step by step, if this is unclearcheckfunction can justreturn num % 2 == 0.