Docsity

Python Programming: Function Calling and Output, Study notes of Computer Science

Toggle sidebar
bg1
FUNCTION (What goes in programming
(black) area)
CALLING THE FUNCTION (What goes in
the command area)
OUTPUT (What JES gives
you in the command area)
def traceMe(a,b):
for i in range(a):
print i*b
traceMe(5,3) 0
3
6
9
12
def trace(a,b,c):
d = b + c
c = b - a
for i in range(a):
a = a - 1
print a, b, c, d
trace(5,1,6) 0 1 -4 7
def addThis(num1, num2):
print num1 + num2
def onceMore(scooby, shaggy, scrappy):
fred = 0
velma = "smart"
daphne = 10
monster = 1
if scooby >= 8:
print fred
if shaggy <> 30:
for i in range(scrappy):
onceMore(3, 10, 6) 11
12
13
14
15
16
10
smart
pf3
pf4
pf5

Partial preview of the text

Download Python Programming: Function Calling and Output and more Study notes Computer Science in PDF only on Docsity!

FUNCTION (What goes in programming (black) area) CALLING THE FUNCTION (What goes in the command area) OUTPUT (What JES gives you in the command area) def traceMe(a,b): for i in range(a): print i*b traceMe(5,3) 0 3 6 9 12 def trace(a,b,c): d = b + c c = b - a for i in range(a): a = a - 1 print a, b, c, d trace(5,1,6) 0 1 -4 7 def addThis(num1, num2): print num1 + num def onceMore(scooby, shaggy, scrappy): fred = 0 velma = "smart" daphne = 10 monster = 1 if scooby >= 8: print fred if shaggy <> 30: for i in range(scrappy): onceMore(3, 10, 6) 11 12 13 14 15 16 10 smart

addThis(daphne, monster) monster = monster + 1 print daphne print velma def another(num): for i in range(num): s = num for z in range(i): s = s10 + num print s another(7) 7 77 777 7777 77777 777777 7777777 def yetAgain(num): for i in range(num): s = num for j in range(i): s = s print s yetAgain(4) 4 8 16 32 def testme(p,q,r): if q > 50: print r value = 10 for i in range(1,p): print "Here we go" value = value - 1 testme(6,99,1001) 1001 Here we go Here we go Here we go Here we go Here we go 5

c = 4 d = 0 for p in range(1,3): d = p + 1 print a ,b, c, d def whatMore(comp, utational, media, yeah): media = media** phrase = str(comp) + " CS " + str(comp) if yeah > 10: for i in range(1, utational): print phrase print media whatMore("Go", 5, 3, 11) Go CS Go Go CS Go Go CS Go Go CS Go 9 def jejoue(skating, curling, hockey): for i in range(skating): curling = curling - hockey print curling print skating, hockey jejoue(5, 27,3) 24 21 18 15 12 5 3 def hablaba(leonardo, donatello, raphael, michelangelo): for i in range(donatello): shredder = 3 for j in range(i): shredder = shredder*10 + leonardo print shredder print michelangelo, raphael, "pizza" hablaba(2, 3, "love", "I") 3 32 322 I love pizza

def namingSucks(num): x = 99 for i in range(1,num,2): x = x - num print x namingSucks(9) 90 81 72 63 def stringStuff(string): for letter in string: print letter + "!" thatThere = len(string) print thatThere stringStuff("amigo") a! m! i! g! o! 5 def listStuff(list): for item in list: new = str(item) + "\t?" print new listStuff(["Where", "in", "the", "world"]) Where? in? the? world? def anotherList(list): newlist = [] for item in list: newlist = newlist + [item] + ["hehe"] print newlist list = [‘Never’, ‘look’, ‘back’] anotherList(list) ['Never', 'hehe', 'look', 'hehe', 'back', 'hehe']