code for chapter 3

This commit is contained in:
Aditya Bhargava
2016-03-02 14:15:37 -08:00
parent 77da85bf4c
commit 8cf108a20c
3 changed files with 30 additions and 0 deletions

View File

@@ -0,0 +1,10 @@
def countdown(i):
print i
# base case
if i <= 0:
return
# recursive case
else:
countdown(i-1)
countdown(5)

View File

@@ -0,0 +1,13 @@
def greet2(name):
print "how are you, " + name + "?"
def bye():
print "ok bye!"
def greet(name):
print "hello, " + name + "!"
greet2(name)
print "getting ready to say bye..."
bye()
greet("adit")

View File

@@ -0,0 +1,7 @@
def fact(x):
if x == 1:
return 1
else:
return x * fact(x-1)
print fact(5)