---
# System prepended metadata

title: 'Python Algorithm 3, Recursion'
tags: [python2021]

---

# Python Algorithm 3, Recursion
###### tags: `python2021`


* 要求 (request)：
    * 格式請依照ex1的標準 (檔名:ex10-1.py, ex10-2.py...，最後將所有檔案壓縮至學號.zip or 學號.7z上傳e3)
    * 輸出檔案內容以TA截圖為標準

---
# Question 1: Sort using List methods 
Given a list: [5204, 2588, 315, 983, 488, 7137, 9690, 708]
Return sorted list: 
(1) Descending: [9690, 7137, 5204, 2588, 983, 708, 488, 315]
(2) Ascending: [315, 488, 708, 983, 2588, 5204, 7137, 9690]
For this question, please use python list **method** to solve the problem.

```python=
list1 = [5204, 2588, 315, 983, 488, 7137, 9690, 708]
list1.sort(reverse = True)
print("Descending:",list1)
list1.sort()
print("Ascending:",list1)
```

# Question 2: Sort 
Using the same list as Question 1 and sort the list (Descending and Ascending).
For this question, you cannot use python list **method** to solve the problem. There are many easy and famous sort algorithm. Please see the video and think how to implement it.
https://www.youtube.com/watch?v=JTPs8rZWBfI

The workflow is a somple example.
![](https://i.imgur.com/z9u4A7Z.png)

```python=
list1 = [5204, 2588, 315, 983, 488, 7137, 9690, 708]

for i in range(len(list1)):
    for j in range(len(list1)-i-1):
        if list1[j]<list1[j+1]:
            temp = list1[j]
            list1[j] = list1[j+1]
            list1[j+1] = temp

print("Descending:",list1)

for i in range(len(list1)):
    for j in range(len(list1)-i-1):
        if list1[j]>list1[j+1]:
            temp = list1[j]
            list1[j] = list1[j+1]
            list1[j+1] = temp

print("Ascending:",list1)
```




# Question 3: Fibonacci's series
Write a function to generate Fibonacci's series (1, 1, 2, 3, 5, 8...). 

![](https://i.imgur.com/keOiuqx.jpg)

```python=
def F_series(n):         
    f1 = 1
    f2 = 1

    for i in range(n-2):
        f = f1 + f2
        f1 = f2
        f2 = f
    
    return(f)

print (F_series(20))