I expected the following code to throw an error as the variable ival
(local variable) is being used outside of its scope i.e., in if condition. I didn't encounter any issues/errors why? Please explain the reason.
rawstr=input('Enter a number')
try:
ival=int(rawstr)
except:
ival=-1
if ival>0:
print('Nice work')
else:
print('Not a Number')
I expected a traceback error saying ival
is not defined.