CSH3.5 MrG 2012.1011 Arguments

2976 days ago by CSH2012

#1) def mystery(x,y): return x//y show(mystery(13,3)) show(mystery(20,5)) show(mystery(-13,-3)) show(mystery(-20,-5)) show(mystery(-13,3)) show(mystery(20,-5)) 
       
\newcommand{\Bold}[1]{\mathbf{#1}}4
\newcommand{\Bold}[1]{\mathbf{#1}}4
\newcommand{\Bold}[1]{\mathbf{#1}}4
\newcommand{\Bold}[1]{\mathbf{#1}}4
\newcommand{\Bold}[1]{\mathbf{#1}}-5
\newcommand{\Bold}[1]{\mathbf{#1}}-4
\newcommand{\Bold}[1]{\mathbf{#1}}4
\newcommand{\Bold}[1]{\mathbf{#1}}4
\newcommand{\Bold}[1]{\mathbf{#1}}4
\newcommand{\Bold}[1]{\mathbf{#1}}4
\newcommand{\Bold}[1]{\mathbf{#1}}-5
\newcommand{\Bold}[1]{\mathbf{#1}}-4
#2) def mystery(x,y): return (x/y).n() show(mystery(13.0,3.0)) show(mystery(20,5)) show(mystery(-13,-3)) show(mystery(-20,-5)) show(mystery(-13,3)) show(mystery(20,-5)) 
       
\newcommand{\Bold}[1]{\mathbf{#1}}4.33333333333333
\newcommand{\Bold}[1]{\mathbf{#1}}4.00000000000000
\newcommand{\Bold}[1]{\mathbf{#1}}4.33333333333333
\newcommand{\Bold}[1]{\mathbf{#1}}4.00000000000000
\newcommand{\Bold}[1]{\mathbf{#1}}-4.33333333333333
\newcommand{\Bold}[1]{\mathbf{#1}}-4.00000000000000
\newcommand{\Bold}[1]{\mathbf{#1}}4.33333333333333
\newcommand{\Bold}[1]{\mathbf{#1}}4.00000000000000
\newcommand{\Bold}[1]{\mathbf{#1}}4.33333333333333
\newcommand{\Bold}[1]{\mathbf{#1}}4.00000000000000
\newcommand{\Bold}[1]{\mathbf{#1}}-4.33333333333333
\newcommand{\Bold}[1]{\mathbf{#1}}-4.00000000000000
#3) def mean(a,b): return (a+b)/2.n() show(mean(2,3)) show(mean(-25,30)) 
       
\newcommand{\Bold}[1]{\mathbf{#1}}2.50000000000000
\newcommand{\Bold}[1]{\mathbf{#1}}2.50000000000000
\newcommand{\Bold}[1]{\mathbf{#1}}2.50000000000000
\newcommand{\Bold}[1]{\mathbf{#1}}2.50000000000000
#4) def swap(x,y): temp=x;x=y;y=temp a=1 b=2 swap(a,b) print a print b 
       
1
2
1
2
#5) def swap2(pair): temp=pair[0];pair[0]=pair[1];pair[1]=temp pair=[1,2] swap2(pair) pair 
       
\newcommand{\Bold}[1]{\mathbf{#1}}\left[2, 1\right]
\newcommand{\Bold}[1]{\mathbf{#1}}\left[2, 1\right]
#6) def swap3(pair): return [pair[1],pair[0]] pair=[1,2] show(swap3(pair)) show(pair) 
       
\newcommand{\Bold}[1]{\mathbf{#1}}\left[2, 1\right]
\newcommand{\Bold}[1]{\mathbf{#1}}\left[1, 2\right]
\newcommand{\Bold}[1]{\mathbf{#1}}\left[2, 1\right]
\newcommand{\Bold}[1]{\mathbf{#1}}\left[1, 2\right]
#7) ax^2+bx+c==0 def quad(a,b,c): d=sqrt(b^2-4*a*c) root1=(-b+d)/(2*a) root2=(-b-d)/(2*a) return [root1,root2] quad(1,2,2) 
       
\newcommand{\Bold}[1]{\mathbf{#1}}\left[i - 1, -i - 1\right]
\newcommand{\Bold}[1]{\mathbf{#1}}\left[i - 1, -i - 1\right]
#8) def double(x=0): return 2*x show(double) show(double()) show(double(3)) 
       
\newcommand{\Bold}[1]{\mathbf{#1}}\hbox{ < function double at 0x4ed6320 > }
\newcommand{\Bold}[1]{\mathbf{#1}}0
\newcommand{\Bold}[1]{\mathbf{#1}}6
\newcommand{\Bold}[1]{\mathbf{#1}}\hbox{ < function double at 0x4ed6320 > }
\newcommand{\Bold}[1]{\mathbf{#1}}0
\newcommand{\Bold}[1]{\mathbf{#1}}6
print(0*16^0) print(2*16^1) print(3*16^2) print(6*16^3) print(13*16^4) print(14*16^5) print(4*16^6) 
       
0
32
768
24576
851968
14680064
67108864
0
32
768
24576
851968
14680064
67108864
print(0*16^0+2*16^1+3*16^2+6*16^3+13*16^4+14*16^5+4*16^6) 
       
82666272
82666272
2*1000^3 
       
\newcommand{\Bold}[1]{\mathbf{#1}}2000000000
\newcommand{\Bold}[1]{\mathbf{#1}}2000000000
2*1024^3 
       
\newcommand{\Bold}[1]{\mathbf{#1}}2147483648
\newcommand{\Bold}[1]{\mathbf{#1}}2147483648
2*1000^3/1024^3.n() 
       
\newcommand{\Bold}[1]{\mathbf{#1}}1.86264514923096
\newcommand{\Bold}[1]{\mathbf{#1}}1.86264514923096
#9) def printNTimes(n,obj="*"): 'print obj n times' count=0 result="" while count<n: result += str(obj) count += 1 print(result) printNTimes(9) 
       
*********
*********
printNTimes(2,"@") 
       
@@
@@