CSH3.3 MrG 2012.1009 Global vs. Local Vars

2976 days ago by CSH2012

#1) local vars live in functions #1) global vars work anywhere 
       
#2) def f(x): root=sqrt(x) return (root+1)/(root-1) f(2) 
       
\newcommand{\Bold}[1]{\mathbf{#1}}\frac{\sqrt{2} + 1}{\sqrt{2} - 1}
\newcommand{\Bold}[1]{\mathbf{#1}}\frac{\sqrt{2} + 1}{\sqrt{2} - 1}
#3) def factorial(n): k=2 f=1 while k<=n: f=f*k k=k+1 return f factorial(10) 
       
\newcommand{\Bold}[1]{\mathbf{#1}}3628800
\newcommand{\Bold}[1]{\mathbf{#1}}3628800
#4a) k=10 def kTimes(x): return k*x kTimes(5) 
       
\newcommand{\Bold}[1]{\mathbf{#1}}50
\newcommand{\Bold}[1]{\mathbf{#1}}50
#4b) k=10 def kTimes2(x): k=5 return k*x kTimes2(5) 
       
\newcommand{\Bold}[1]{\mathbf{#1}}25
\newcommand{\Bold}[1]{\mathbf{#1}}25