OK, I fixed it. Apparently I was overriding a reserved word in question #1
when I wrote a function called concat(). All I had to do to fix the
permalink issue was to rename that function concatIt()!
Sorry for the NOOB issue, I should have known that was a reserved word. I
guess that's what I get for teaching an intro programming course in python.
What confused me was that the code executed fine, so I thought permalink
would work automagically.
Here's the new code:
#CSH304 More About Pythonic Functions! MrG
show('#1) concatenate 2 strings')
def concatIt(s1,s2):
return s1+' '+s2
show('concatIt("al","garcia")=',concatIt("al","garcia"))
show('')
show('#2) draw a house!')
def printHouse():
print(" /\\\n/__\\\n| |\n|__|")
#print(" /\\")
#print("/__\\")
#print("| |")
#print("|__|")
printHouse()
show('')
show('#3) pad your strings!')
def rightJustify(s,w):
'pad s with correct number of spaces in front'
return ' '*(w-len(s))+s
show(rightJustify("bob",7))
show(rightJustify("bobbie",7))
show(rightJustify("Baldwin",7))
show(rightJustify("High",7))
show('')
show("#4a) what's wrong with this output?")
def print10Stars():
print 10*'*'
show('print10Stars()=',print10Stars())
show('')
show('#4b) how to get rid of None?')
def make10Stars():
return 10*'*'
show('make10Stars()=',make10Stars())
show('')
show('#5) predict the output')
def printTriangle(n,ch):
while n>0:
show(n*ch)
n-=1
return 1
show("printTriangle(2,'*')=",printTriangle(2,'*'))
show("printTriangle(3,'#')=",printTriangle(3,'#'))
show("printTriangle(2,'*')+printTriangle(3,'#')=",printTriangle(2,'*')+printTriangle(3,'#'))
show('')
show('#6) predict the output')
def sum1ToN(n):
if n>0:
return n*(n+1)//2
show('sum1ToN(6)=',sum1ToN(6))
show('sum1ToN(0)=',sum1ToN(0))
show('sum1ToN(-3)=',sum1ToN(-3))
show('')
show('#8) what is the output?')
#show('len(0)=',len(0))
show("len('0')=",len('0'))
show("len('''0''')=",len('''0'''))
show("len('''''')=",len(''''''))
show('len([0])=',len([0]))
show('len([])=',len([]))
#show('len((0))=',len((0)))
show('len(range(0)=',len(range(0)))
Thanx,
AJG
--
You received this message because you are subscribed to the Google Groups
"sage-cell" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/sage-cell/d5fd7f95-bce5-4301-82d2-d2d47c75e086%40googlegroups.com.