---
# System prepended metadata

title: Automation interview question

---

# Automation interview question
1. [Easy]給予一個輸入值n，請印出層數為n的等腰三角形
```
n=input()
for layer in range(n):
    for space_num in range(n-layer+1):
        print(" ",end="")
    for star_num in range(2*i+1):
        print("*",end="")
    print("")
```
2. [Medium]求兩正整數a,b的最大公因數。
```
##Answer 1
if a<b:
    tmp=a
    a=b
    b=tmp
while(a%b!=0)
    b=a%b
    a=b
print b
```
```
##Answer 2
if a<b:
    tmp=a
    a=b
    b=tmp
start=b/2
divisor=1
for i in range(start,0,-1):
    if a%i== 0 and b%i==0:
        divisor=i
        break
print divisor
```
3. [Medium]請找出任意數字陣列[a1,a2,...,an]中的中位數
ex: input: [1,3,2,4], output: 2.5
```
l = [1,3,2,4]
tmp_list = sort[l]
length = len(tmp_list)
if length%2 == 0:
    print (tmp_list[length/2]+tmp_list[length/2+1])/2
else:
    print tmp_list[length/2+1]
```

