You are on page 1of 10

奧冠教育中心

OLYMPIAD CHAMPION EDUCATION CENTRE


Room 309-310, 8 Jordan Road, Yau Ma Tei, Kowloon, Hong Kong SAR, CHINA
Tel (852) 3153 2028 / 9310 1240 Fax (852) 3153 2074
Website: www.olympiadchampion.com Email: olympiadchampion@gmail.com

香港國際編程競賽初賽 2020 – 2021


HONG KONG INTERNATIONAL
COMPUTATIONAL OLYMPIAD
HEAT ROUND 2020 - 2021

Python
時限:60 分鐘
Time allowed: 60 minutes
試題
Paper
考生須知:
Instructions to Contestants:
1. 本卷包括 試題 乙份,試題紙不可取走。
Each contestant should have ONE Question-Answer Book which CANNOT be taken
away.
2. 本卷共 20 題,答對得 4 分,空題得 0 分,答錯倒扣 1 分。
There are a total of 20 questions in this Question-Answer Book. Four points for
correct answers. No points for incorrect answers. ONE penalty point will be
deducted for incorrect answers.
3. 請將答案寫在 答題紙 上。
All answers should be written on ANSWER SHEET.
4. 比賽期間,小學組不得使用計算工具,中學組可以使用計算工具。
During the contest, NO calculators can be used for PRIMARY GROUP but calculators can be
used for SECONDARY GROUP.
5. 本卷中所有圖形不一定依比例繪成。
All figures in the paper are not necessarily drawn to scale.
6. 比賽完畢時,本試題會被收回。
This Question-Answer Book will be collected at the end of the contest.

本試題不可取走。
THIS Question-Answer Book CANNOT BE TAKEN AWAY.
未得監考官同意,切勿翻閱試題,否則參賽者將有可能被取消資格。
DO NOT turn over this Question-Answer Book without approval of the examiner.
Otherwise, contestant may be DISQUALIFIED.
請將答案寫在 答題紙 上。
All answers should be written on the ANSWER SHEET.

選擇題(第 1 至 20 題)(答對得 4 分,空題得 0 分,答錯倒扣 1 分)


Multiple Choice Questions (1st ~20th) (Four points for correct answers. No points for incorrect answers. ONE
penalty point will be deducted for incorrect answers.)

1. Which of the following is a valid list?


以下哪一項是符合語法的序列?
A. [ 3 = 5, 4 = 0, 6 = 10 ]
B. [ 3:5, 4:0, 6:10 ]
C. [[0][0:4]]
D. [ "A", "B", len=6 ]
E. None of the above
以上皆不是

2. Which of the following statements equals to False?


以下哪一項表達式的數值為否?
A. False and False | True
B. True && not False || False
C. True || False and not True
D. False or True and True
E. None of the above
以上皆不是

3. Which of the following features does not exist as of Python 3.7?


截至 Python 3.7 為止, Python 沒有以下哪一項特色?
A. f-string
B. breakpoint()
C. dataclass
D. walrus operator :=
E. None of the above
以上皆不是

4. Which of the following is not a Python built-in types?


以下哪一項不是 Python 內建類別?

A. int
B. double
C. complex
D. list
E. All of the above
以上皆是內建類別
請將答案寫在 答題紙 上。
All answers should be written on the ANSWER SHEET.

5. What is the output of the following program?


以下程式的輸出是?
class A: pass
def main():
print(callable(main) == callable(A))
main()

A. True
B. False
C. None
D. Runtime Error
運行錯誤
E. None of the above
以上皆不是

6. What is the value of the expression -20 // -7 % 3?


-20 // -7 % 3 的值是?
A. -1
B. -2
C. 0
D. 1
E. 2

7. What is the output of the following program?


以下程式的輸出是?

def func(a = [], b = 2):


a.extend(range(b))
return len(a)

def main():
print(func(b = func()))

main()
A. 1
B. 2
C. 3
D. 4
E. None of the above (including runtime error)
以上皆不是 (包括運行錯誤)
請將答案寫在 答題紙 上。
All answers should be written on the ANSWER SHEET.

8. Suppose there exists a file "a.py" in the working directory.


假設工作目錄中有一個檔案 "a.py"
Which of the following expressions evaluates to True in Windows (after importing the correct modules)?
以適當的模組已匯入的情況下,執行環境為 Windows 時,以下哪一句表達式的值為 True?

import os
import pathlib

A. os.stat("a.py").st_ctime == pathlib.Path("a.py").stat().st_birthtime
B. pathlib.Path("a.py").stat().st_birthtime == os.path.getctime("a.py")
C. os.path.getbirthtime("a.py") == pathlib("a.py").stat().st_birthtime
D. os.stat("a.py").st_ctime == os.path.getctime("a.py")
E. None of the above
以上皆不是

9. Which of the following expressions evaluates to True?


以下哪一項表達式的數值為 True?
A. double(3.213322459373) == 3.213322459373
B. float(3.2210593) == 3.2210593
C. int(3.221) == 3.221
D. All of the above
以上皆是
E. None of the above
以上皆不是
請將答案寫在 答題紙 上。
All answers should be written on the ANSWER SHEET.

10. What is the output of the following code?


以下程式的輸出是?
class A:
__a = 0

@property
def a(self): return eval(self.__a)

@a.setter
def a(self, value): self.__a = value

a = A()
b = 2
c = 3
a.a = "b + c"
b = 5
print(a.a)

A. 2
B. 3
C. 5
D. 8
E. None of the above
以上皆不是

11. What is the value of the following expression?


以下表達式的值是?
list(dict.fromkeys([3,2,2,1,1,2]))

A. { 3: 2, 2: 1, 1: 2 }
B. [3, 2, 2, 1, 1, 2]
C. [3, 2, 1]
D. [(3, 2), (2, 1), (1, 2)]
E. None of the above
以上皆不是
請將答案寫在 答題紙 上。
All answers should be written on the ANSWER SHEET.

12. What is the output of the following code?


以下程式的輸出是?

a = 100,000,000
print(str(a)[1])
A. 0
B. 1
C. None
D. (
E. None of the above
以上皆不是

13. What is the output of the following code after user input "10" (without the quotes)?
以下程式在用戶輸入 "10" (不包括引號) 後的輸出是?

a = input()
b = a + 20
print(b[1])
A. 0
B. 1020
C. None
D. 30
E. None of the above
以上皆不是

14. What is the value of the following expression?


以下表達式的值是?
len([range(5)][-2:])
A. 1
B. 5
C. 0
D. -2
E. None of the above
以上皆不是
請將答案寫在 答題紙 上。
All answers should be written on the ANSWER SHEET.

15. What is the output of the following code?


以下程式的輸出是?

class A:
def __enter__(self):
print(end="OK")
def __exit__(self, a, b, c):
print(end="HI")

with A():
print(end="BYE")

A. OKHIBYE
B. HIOKBYE
C. OKBYEHI
D. HIBYEOK
E. None of the above
以上皆不是
請將答案寫在 答題紙 上。
All answers should be written on the ANSWER SHEET.

16. What is the output of the following code?


以下程式的輸出是?

for i in range(13):
if i // -3 == -1:
break
print(i // -3)
else:
print("HI")

A. 0
B. 1
C. 0
-1
-1
-1
-2
-2
-2
-3
-3
-3
-4
-4
-4
HI
D. HI
E. None of the above
以上皆不是
請將答案寫在 答題紙 上。
All answers should be written on the ANSWER SHEET.

17. What is the output of the following program?


以下程式的輸出是?

import functools
a = [1, 2, 3, 4, 5]
print(functools.reduce(lambda x, y: x * y // 2, a))

A. 0
B. 5
C. 7.5
D. [1, 2, 3, 4, 5]
E. None of the above
以上皆不是

18. What is the value of the following expression?


以下程式的輸出是?
list(filter(lambda x: x % 3, range(10)))[:-2][-2]

A. 3
B. 4
C. [0, 1, 4, 5, 7, 8]
D. [4, 5]
E. None of the above
以上皆不是

19. What is the output of the following program?


以下程式的輸出是?

a = list(range(5), range(2))
a.reverse()
print(a[0][0])

A. range(0, 5)
B. range(0, 2)
C. 1
D. 4
E. None of the above
以上皆不是
請將答案寫在 答題紙 上。
All answers should be written on the ANSWER SHEET.

20. What is the output of the following program?


以下程式的輸出是?

a = 4
def func(a = 6):
print(end=str(a))
a = 2
a = 3
func(a = 1)
print(end=str(a))

A. 61
B. 42
C. 13
D. 11
E. None of the above
以上皆不是

~ 全卷完 ~
~ End of Paper ~

You might also like