CISC101 Lesson 22
CISC101 Lesson 22
Variable Scope
Variable scope is the block of code in which you can access it
(x) local variable if defined inside a piece of code
-
Example
Def fun1():
B=2
Def fun2()
A=5
Print(A)
Print(B)
Fun2() >> 5 then error because B wasnt defined
Def fun1()
B=2
Def fun2()
B=8
Fun1()
Print(b)
Fun2()
8 calling a function wouldnt matter because it looks at the local variable
Variable Lifetime
-
Constants
-
Errors
-
Syntax error is a problem with how you wrote a line a code, before it runs
Run-time errors happen because of unforeseen problems when you run the
code
Exceptions
-
Catching exceptions
Try:
Try_statements
Except exception:
Except_statements
Exception is the name of the exception you are catching
Try_statements is code that could generate a run time error. The code here stops as
soon as there is an error