forked from inspirezonetech/TeachMePythonLikeIm5
-
Notifications
You must be signed in to change notification settings - Fork 0
/
recursive_func.py
23 lines (20 loc) · 947 Bytes
/
recursive_func.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# ------------------------------------------------------------------------------------
# Tutorial: How to make a recursive function
# A recursive function is a function that calls itself
# ------------------------------------------------------------------------------------
# find the factorial of a user entered number
# the 'def' keyword is used to declare a function. the structure of a function is:
mul = 1
def fact(num):
if num == 1:
return num
else:
return num * fact(num - 1)
num = int(input('Enter a number to get the factorial of it: '))
if num == 0:
print("Factorial of 0: 1")
else:
print("Factorial of ", num, ":", fact(num))
# -----------------------------------------------------------------------------------
# Challenge: create a recursive function that makes a countdown from a user entered number till zero
# ------------------------------------------------------------------------------------