This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| """ | |
| Factorial | |
| Topic 11: Question 1 | |
| A function that calls itself is said to be recursive. The creation of recursive functions is a powerful technique to solve problem that can be broken down into smaller or simpler form. One common use is to find the factorial of a number. The factorial of a number N is simply the number multiplied by the factorial of (N-1). Complete the code given below to calculate and returns the factorial of a numeber. | |
| Examples | |
| >>> factorial(5) | |
| 120 | |
| >>> factorial(1) | |
| 1 | |
| >>> factorial(0) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # -*- coding: utf8 -*- | |
| def insert_sort(input_array): | |
| """ asc ord | |
| 每次处理就是将无序数列的第一个元素与有序数列的元素从后往前逐个进行比较,找出插入位置,将该元素插入到有序数列的合适位置中。 | |
| """ | |
| if isinstance(input_array,list) == False: | |
| print 'Error: When you use insert_sort function, please make sure your argument is a list' | |
| return None | |
| for j in xrange(1,len(input_array)): |