Difference between revisions of "CSC111 Exercises with Global Variables"

From dftwiki3
Jump to: navigation, search
Line 2: Line 2:
 
----
 
----
 
<br />
 
<br />
Predict the output of the following programs, of if they crash, indicate why.
+
{|
<br />
+
|
==Exercise1==
 
 
<br />
 
<br />
 
<source lang="python">
 
<source lang="python">
Line 17: Line 16:
 
</source>
 
</source>
 
<br />
 
<br />
==Exercise2==
+
|
<br />
+
<source lang="text">
<source lang="python">
+
>>>
 
+
A =  3
def f1( x ):
+
f1 30 3
    print( "f1", x, A )
+
>>>
 
 
f1( 30 )
 
print( "A = ", A )
 
 
 
 
</source>
 
</source>
 +
|}
  
<br />
 
 
<br />
 
 
<br />
 
<br />
 
<br />
 
<br />

Revision as of 18:00, 24 April 2014

--D. Thiebaut (talk) 15:57, 24 April 2014 (EDT)




A = 3

def f1( x ):
    print( "f1", x, A )

print( "A = ", A )
f1( 30 )


>>> 
A =  3
f1 30 3
>>>