---
# System prepended metadata

title: Python Algorithm 2
tags: [python2021]

---

# Python Algorithm 2
###### tags: `python2021`


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

---

# Question 1
Please write a program, which can remove the duplicate elements of list. For example, given a list [2,2,3,3,4,4,53,4,5,2]. Please print out a sorted and distinct results: [2,3,4,5,53]
:::info
Note: you can use sorted() and list.sort(), But set() series functions are NOT allowed.
:::

# Question 2
In computer, all information is represented and stored in binary. We can use binary (二進位) number to represent a decimal (十進位) number.

For example:
The binary code “101” converted to decimal number is 5 = 1 x  2^0^+ 0 x 2^1^ + 1 x 2^2^
The binary code “10010” converted to decimal number is 18 = 0 x 2^0^ + 1 x 2^1^ + 0 x 2^2^ + 0 x 2^3^ + 1 x 2^4^
```python=
def BinaryConvert(BinaryString):
    ConvertedNumber = 0
    #Please complete this function
    return ConvertedNumber
```
# Question 3
Here is a factorial program:
```python=
N = int(input("N: "))
i =1
sum = 1
while i<=N:
    sum=sum*i
    i=i+1
print(sum)
#For example: input 5, print out 120
```
Please rewrite the program using “for” loop. (“while” loop is not allowed)