下列何者不可能是 print(random.randrange(0,15,3)) 的顯示結果 ?
15
0
12
3
對於檔案指標函數的描述,何者有誤?
seek將指標移到位置n
tell()傳回目前指標位置
next()將指標移到下一行
next(0)將指標移至開頭
執行以下程式,但是file1.txt不存在
f=open('file1.txt','r')
會產生何種錯誤
ZeroDivisionError
IOError
ValueError
以上皆非
NameError
對於字典的描述,何者錯誤?
查詢容易: 輸入key(鍵),可快速傳回value(值)
鍵值為唯一
當重複輸入值,前面值會被覆蓋
需要排序
元素為鍵-值,利用鍵來取得值
使用dict1.get("apple", 100), 傳回apply的key值 若apple不存在,會傳回?
true
-1
false
100
執行下列程式,結果何者正確?
datas=[3,5,2,1]
n=len(datas) datas)-1
for i in range(0,n):
for j in range(0,n n-i):
if (datas[j]>datas[j+1]):
datas[j],datas[j+1]=datas[j+1],datas[j]
print(datas)
[1,2,3,5]
[ 5,3,2,1]
[3,5,2,1]
[3,5,1,2 ]
對於將緩衝區的資料寫到檔案的描述,何者不正確
read()時也會執行
會視緩衝區的狀況自動執行
可用flush()執行
檔案close前會自動執行
如果作業系統是繁體中文 Windows 系統,預設的編碼為何?
UTF-8
unicode
GB2312
cp950
使用in 查詢字典內是否有此項目, 如“Apple” in dict1 若存在,傳回何值?
index
value
key
下列對於字典dict1的指令,何者不會傳回一個串列list?
dict1.copy()
dict1.items()
dict1.values()
dict1.keys()
在 try…except…finally 敘述中, 無論例外有沒發生都會執行下列 那些程式區塊?
try
except
finally
以上皆是
下列何者不可能是 print(random.randint(1,10)) 的顯示結果 ?
5
8
10
2
num=[256,731,943,389,142,645,829,945]
name=[" 林小虎", "王中森 "," 邵木淼 "," 李大同 ", "陳子孔 "," 鄭美麗", "曾溫柔 "," 錢來多 "]
no = 100
IsFound=False
for i in range(len(name)): # 逐一比對搜尋
if (num[i]==no): # 號碼相符
IsFound=True # 設旗標為 True
break # 結束比對
if (IsFound==True):
print(" 中獎者的姓名為: :",name[
else:
print(" 無此中獎號碼! !")
print(" 共比對 %d 次 " %(i+1))
上述程式使用何種方法?
循序搜尋
二分搜尋
泡沫搜尋
建立dictionary的方法,以下哪一個是錯的?
dict1 =dict(20=“Apple”, 30=“Banana”)
dict1 =dict(“Apple”:20, “Banana”:30)
dict1={}
dict1 =dict(“Apple”=20, “Banana”=30)
dict1 ={“Apple”:20, “Banana”:30}
print(max([4,8,3,9,2,6])) 顯示為何?
6
4
9
Python 提供何種內建函式,可以開啟指定的檔案,以便進行檔案內
容的讀取、寫入或修改?
open()
file()
input()
output()
print("hospital".startswith("ho")) 顯示的結果為何?
True
False
ho
hospital
執行下列程式,結果何者正確 ?
list1 = [1,2,3,4,5,6]
m = list1.pop()
n = list1.pop(2)
m=2, n=3
m=6, n=3
m=1, n=6
m=6, n=2
print("hospital".replace("s","t")) 顯示的結果為何?
hotpital
hotpisal
hospisal
要刪除字典dict1中,鍵為Apple的項目,要下何指令?
clear dict1[“Apple”]
remove dict1[“Apple”]
del dict1
dict1.clear()
del dict1[“Apple”]