Reputation: 1
i have this function that works as intended except for the fact that the last print instruction outside the while cycle (print("why don't you print?")) never get executed and i don't understand why. after the break, the code execution should move forward.
def eval_cycle():
done = 'done'
last_expression = ' '
while True:
dato = eval(input('Insert an expression: '))
if dato == done:
print("Last expression is: ", last_expression)
return dato
break
last_expression = dato
print(dato)
print("why don't you print?")
Upvotes: 0
Views: 36
Reputation: 36596
When you return
it immediately returns control flow out of the function.
Nothing in the function after that is executed.
As a sidenote, you may want to read the expression in as a string and then execute it. That way you can store it in last_expression
rather than just the result of eval
ing the expression.
Upvotes: 1