# 期中考的程式考題 選擇題答案

```選擇題

num=int(input(“Enter a number with 1 or 2 digits:”))
digits=”0”
if num &gt;0:
(1)
digits=’1’
(2)
digits=’2’
(3)
digits=’&gt;2’
print(digits + “digits.”)
else:
print(“The number is not a positive number”)
(1) A. if num&lt;10: B. if num&lt;10 C. if num&gt;-10 and num&lt;10: D. if num&gt;-100
and num &lt;100:
(2) A. if num&lt;100: B. if num &lt;100 C. elif num&lt;100: D. elif num&gt;-100 and
num&lt;100:
(3) A. elif num &gt;100 B. if: C: else: D: elif:

backwards_pname=input(“請輸入顛倒字母順序的產品名稱:”)
forwards_pname=””
for i in
(4) :
forwards_pname +=
(5)
print(forwards_pname)
(4) A. backwards_pname B. len(backwards_pname)
C. range(0,len(backwards_pname),-1)
D. range(len(backwards_pname)-1,-1,-1)
(5) A. backwards_pname[i-1] B. backwards_pname[len(forward_pname)-1]
C. backwards_pname[len(backwards_pname)-len(forwards_pname)]
D. backwards_pname[i]

product_no=””
(6)
(7)
product_no=input(“Enter product number(dd-dddd):”)
parts=product_no.split(‘-‘)
if len(parts)==2:
if len(parts[0])==2 and len(parts[1])==4:
if parts[0].isdigit() and parts[1].isdigit():
(8)
print(valid)
(6) A. while product_no ==””: B. while product_no != “”:
(7) A. valid=False B. valid=True
(8) A. valid=False B. valid=True
(9) print(list(range(2,-11,-3))) 結果為 A. [2, -1, -4, -7]
1, -4, -7, -10] D. [2, -1, -7, -10]
(10) for i in range(1,11):
if i==6:
break
print(i,end=’ ’)

B. 1 2 3 4 5
B. [2, -1, -4, -7, -10]
C. [-
C. 1 3 5 7 9 D. 2 4 6 8 10
(11)你為學校設計一個 python 應用程式，在 classroom 的清單中包含 60 個同學

A. classroom[0:-2]
B. classroom[1:-3]
C. classroom[0:-3]
D. classroom[0:-4]
(12) 當我們要使用 math 模組前須使用下列哪個指令?
A. input math B. print math C. type math
D. import math
(13) list1=[1,2,3]
list2=[4,5,6]
list3=list2+list1
list4=list3*2
print(list4)
A. [[4,5,6],[4,5,6],[1,2,3],[1,2,3]]
B. [1,2,3,4,5,6,1,2,3,4,5,6]
C.[4,5,6,1,2,3,4,5,6,1,2,3] D.[[4,5,6,1,2,3],[4,5,6,1,2,3]]
(14) listA=[1,4,12,3,24]
print(‘12’ in listA)
A. True B. False
Ans:
1.A 2.C 3.C 4. D 5.D 6.A 7.A
8.B 9.B 10.B 11.C 12.D 13.C 14.B
```