CM 3.4 More Functions MrG 2011.1020

3689 days ago by calcpage123

def distance(x1,y1,x2,y2): return sqrt((x2-x1)^2+(y2-y1)^2) distance(4,0,0,3) 
       
\newcommand{\Bold}[1]{\mathbf{#1}}5
\newcommand{\Bold}[1]{\mathbf{#1}}5
distance(0,3,4,0) 
       
\newcommand{\Bold}[1]{\mathbf{#1}}5
\newcommand{\Bold}[1]{\mathbf{#1}}5
def rotate(item): item.append(item.pop(3)) item=[1,2,3,4,5] rotate(item) item 
       
\newcommand{\Bold}[1]{\mathbf{#1}}\left[1, 2, 3, 5, 4\right]
\newcommand{\Bold}[1]{\mathbf{#1}}\left[1, 2, 3, 5, 4\right]
print(rotate(item)) 
       
None
None
#1) def makeString(one, two): return one+" "+two makeString("john","public") 
       
\newcommand{\Bold}[1]{\mathbf{#1}}\hbox{john public}
\newcommand{\Bold}[1]{\mathbf{#1}}\hbox{john public}
#2) def printHouse(): print(" /\\\n/__\\\n| |\n|__|") printHouse() 
       
 /\
/__\
|  |
|__|
 /\
/__\
|  |
|__|
def printHouse(): print(" /\\") print("/__\\") print("| |--|") print("|__|--|") printHouse() 
       
 /\
/__\
|  |--|
|__|--|
 /\
/__\
|  |--|
|__|--|
#3) def rightJustify(s,w): return " "*w+s rightJustify("Baldwin",10) 
       
\newcommand{\Bold}[1]{\mathbf{#1}}\hbox{          Baldwin}
\newcommand{\Bold}[1]{\mathbf{#1}}\hbox{          Baldwin}
#4) def print10Stars(): print(10*'*') print10Stars() 
       
**********
**********
print(print10Stars()) 
       
**********
None
**********
None
def make10Stars(): return(10*'*') make10Stars() 
       
\newcommand{\Bold}[1]{\mathbf{#1}}\hbox{**********}
\newcommand{\Bold}[1]{\mathbf{#1}}\hbox{**********}
print(make10Stars()) 
       
**********
**********
2==2 
       
\newcommand{\Bold}[1]{\mathbf{#1}}{\rm True}
\newcommand{\Bold}[1]{\mathbf{#1}}{\rm True}
2<1 
       
\newcommand{\Bold}[1]{\mathbf{#1}}{\rm False}
\newcommand{\Bold}[1]{\mathbf{#1}}{\rm False}
2>1 
       
\newcommand{\Bold}[1]{\mathbf{#1}}{\rm True}
\newcommand{\Bold}[1]{\mathbf{#1}}{\rm True}
2>=2 
       
\newcommand{\Bold}[1]{\mathbf{#1}}{\rm True}
\newcommand{\Bold}[1]{\mathbf{#1}}{\rm True}
2<>2 
       
\newcommand{\Bold}[1]{\mathbf{#1}}{\rm False}
\newcommand{\Bold}[1]{\mathbf{#1}}{\rm False}
10<=5 
       
\newcommand{\Bold}[1]{\mathbf{#1}}{\rm False}
\newcommand{\Bold}[1]{\mathbf{#1}}{\rm False}
#5) def printTriangle(n, ch): while n > 0: print(n * ch) n -= 1 printTriangle(6,'*') 
       
******
*****
****
***
**
*
******
*****
****
***
**
*
printTriangle(5,'#') 
       
#####
####
###
##
#
#####
####
###
##
#
#6 def sum1ToN(n): if n>0: return n*(n+1)/2 print(sum1ToN(3)) 
       
6
6
print(sum1ToN(0)) 
       
None
None
#8) #show(len(0)) show(len('0')) show(len('''0''')) show(len('''''')) show(len([0])) show(len([])) #show(len((0))) show(len(range(0))) 
       
\newcommand{\Bold}[1]{\mathbf{#1}}1
\newcommand{\Bold}[1]{\mathbf{#1}}1
\newcommand{\Bold}[1]{\mathbf{#1}}0
\newcommand{\Bold}[1]{\mathbf{#1}}1
\newcommand{\Bold}[1]{\mathbf{#1}}0
\newcommand{\Bold}[1]{\mathbf{#1}}0
\newcommand{\Bold}[1]{\mathbf{#1}}1
\newcommand{\Bold}[1]{\mathbf{#1}}1
\newcommand{\Bold}[1]{\mathbf{#1}}0
\newcommand{\Bold}[1]{\mathbf{#1}}1
\newcommand{\Bold}[1]{\mathbf{#1}}0
\newcommand{\Bold}[1]{\mathbf{#1}}0