Font size
Worksheetspython its
Total questions: 89
Worksheet time: 56mins
請問哪兩種資料類型儲存在第01行的rooms清單中?
布林值和字串
浮點數和布林值
整數和字串
浮點數和整數
請問第02行的room是哪種資料類型?
bool
float
int
string
為什麼第03行無法尋找房間?
無效的語法
不符合的資料類型
命名錯誤的變數
try陳述式可以包含一個或多個except子句。
正確
錯誤
try陳述式可以包含finally子句,但不含except子句。
正確
錯誤
try陳述式可以包含finally子句以及except子句。
正確
錯誤
try陳述式可以包含一個或多個finally子句。
正確
錯誤
※您撰寫了以下這段程式碼:
import datetime
d = datetime.datetime(2017, 4, 7)
print('{:%B-%d-%y}'.format(d))
執行程式。請問輸出為何?
A. 04-07-17
A. 2017-APRIL-07
A. APRIL-07-17
A. 04-07-2017
請問您應該針對第05行和第06行撰寫哪些程式碼?
05 if line != '\n':
06 if line != "":
05 if line != '':
06 if line != "":
05 if line != '\n':
06 if line != None:
05 if line != '':
06 if line != "\n":
學校正在開發一個程式記錄學生資料並且儲存到資料庫。在這個程式中將會處理各種型態的資料。以下的變數宣告後它們的資料類別依序是?
age = 12
minor = False
name = "David"
weight = 64.5
zip = "545"
A. int、bool、str、float、str
A. int、str、str、float、int
A. float、str、str、float、str
A. int、bool、str、int、int
在第04行,擷取目前的日期
A. now=datetime()
A. now=datetime.date()
A. now=datetime.datetime.now()
A. now=new date()
在第04行,擷取目前的日期
A. today=now.strftime("%A")
A. today=now.strftime("%B")
A. today=now.strftime("%W")
A. today=now.strftime("%Y")
在第15行,計算當週剩餘天數
A. daysLeft=now-now.weekday()
A. daysLeft=today-today.weekday()
A. daysLeft=6-now.weekday()
A. daysLeft=6-datetime.datetime.weekday()
letter_grade='A'
A. if grade <=90:
A. if grade >=90:
A. elif grade >90:
elif grade >=90:
letter_grade='B'
A. if grade >80:
A. if grade >=80:
A. elif grade >80:
elif grade >=80:
letter_grade='C'
A. if grade >70:
A. if grade >=70:
A. elif grade >70:
elif grade >=70:
letter_grade='D'
A. if grade >65:
A. if grade >=65:
A. elif grade >65:
elif grade >=65:
某間銀行必須產生一份報表來顯示所有客戶每天的平均*。這份報表必須截斷餘額的小數部分。請問哪兩個程式碼片段可達成目標?
A. average_blance = int(total_deposits/number_of_customers)
A. average_blance = total_deposits//number_of_customers
A. average_blance = total_deposits**number_of_customers
A. average_blance = float(total_deposits//number_of_customers)
(1)
A. !="n":
=="n":
=="y":
(2)
=="Sunday":
A. >="Sunday":
A. is "Sunday":
(3)
=="Thursday":
B. <="Thursday":
B. is "Thursday":
請問您應該在第02行撰寫哪個程式碼?
A. input("name")
A. name = input()
A. input(name)
A. name = input
在 Python 程式中如果希望使用者輸入時,即使用輸入了小數程式也能自動轉為整數來進行運算,你應該使用以下哪個程式碼片段?
A. total = input("請輸入總數?")
A. total = int(input("請輸入總數?"))
A. total = str(input("請輸入總數?"))
A. total = float(input("請輸入總數?"))
您正在撰寫一個必須執行下列工作的Python函式:
● 接受清單和字串做為參數。
● 在清單中搜尋字串。
● 如果字串存在清單中,則列印一則訊息,指出找到字串,然後停止逐一查看清單。
● 如果字串不在清單中,則列印一則訊息,指出找不到字串。
請問您應該按什麼順序排列程式碼片段以完成此函式?
(1)
A. float(input("Enter next rating (1-5, -1 for done)"))
A. input "Enter next rating (1-5, -1 for done)"
A. input("Enter next rating (1-5, -1 for done)")
A. print("Enter next rating (1-5, -1 for done)")input "Enter next rating (1-5, -1 for done)"
(2)
A. console.input("The average star rating for the new coffee is:"
A. output("The average star rating for the new coffee is:"
A. print("The average star rating for the new coffee is:"
A. printline("The average star rating for the new coffee is:"
(3)
A. {average, '.2f}
A. format.average.{2d}
A. format(average,'.2d'))
A. format(average,'.2f))
(1)
elif
if
for
else
(2)
elif
if
for
else
(3)
elif
if
for
else
(4)
elif
if
for
else
(5)
or
and
not
(6)
elif
if
for
else
(7)
elif
if
for
else
以上程式碼的空格中的程式碼依序為:
A. (1) if num / 2 == 0: (2) if num / 2 != 0:
A. (1) if num % 2 == 0: (2) else:
A. (1) if num / 2 = 0: (2) if num / 2 <> 0:
A. (1) if num % 2 == 0: (2) elif num / 2 == 0:
請問您應該按什麼順序排列程式碼片段以完成此函式?請將所有程式碼片段移至作答區中,然後按照正確的順序排列。
您撰寫了以下這段程式碼:
list_1 = [1,2]
list_2 = [3,4]
list_3 = list_1 + list_2 list_4 = list_3 * 3 print(list_4)
您執行程式碼。請問輸出值為何?
A. [1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4,]
A. [[1, 2, 3, 4], [1, 2, 3, 4], [1, 2, 3, 4]]
A. [3, 6, 9, 12]
A. [[1, 2], [3, 4], [1, 2], [3, 4], [1, 2], [3, 4]]
您正在撰寫程式碼來產生一個最小值5與最大值11的隨機整數。
請問您應該使用哪兩個函式?每個正確答案都是一個完整的解決方案。
A. random randint(5, 12)
A. random randrange(5, 12, 1)
A. random randint(5, 11)
A. random randrange(5, 11, 1)
(1)
A. for col in range(13):
A. for col in range(2,13):
A. for col in range(2,12,1):
A. for col in range(12):
(2)
A. for row in range(13):
A. for row in range(2,12,1):
A. for row in range(2,13):
A. for row in range(12):
你為公司設計了一個 Python 應用程式,在 members 的清單中包含了 50 位會員的姓名,最後 5 名是 VIP 會員。
你需要分割清單內容顯示除了 VIP 會員以外的一般會員,你可以利用以下哪二個程式碼達成?
A. members [-5 : 0]
A. members [0 : -5]
A. members [1 : -5
A. members [ : -5]
A. members [1 : 5]
print("答案位置 ".format(fields[0], eval(fields[1]), eval(fields[2])))
print("
{10:0}
{0:10}
{1:5.1f}
{2:7.2f}
您正在為學校開發一個Python應用程式。此應用程式必須讀取並寫入資料至文字檔案。如果檔案不存在,此應用程式就必須建立檔案。如果檔案含有內容,此應用程式就必須刪除內容。
請問您應該使用哪個程式碼片段?
A. open("local_data", "w+")
A. open("local_data", "r")
A. open("local_data", "r+")
A. open("local_data", "w")
您正在建立一個函式, 將傳入函式的數字當作浮點數(float)值操作。此函式必須執行下列工作:
● 提取浮點數(float)的絕對值
● 移除整數後面的任何小數點。
請問您應該使用哪兩個數學函式?每個正確答案都是解決方案的一部分。(請選擇2個答案。)請注意:每一個答對的項目都能獲得部分分數。
math.floor(x)
math.fabs(x)
math.frexp(x)
math.fmod(x)
(1)
(a)
(2)
(a)
1. 若要測試變數a與b的值是否相同,請使用:
A. assertEqual(a,b)
A. assertTure(x)
A. assertIs(a,b)
A. assertIn(a,b)
1. 若要測試物件a與b是否相同,請使用:
A. assertEqual(a,b)
A. assertTure(x)
A. assertIs(a,b)
A. assertIn(a,b)
1. 若要測試清單中是否存在某個值,請使用:
A. assertEqual(a,b)
A. assertTure(x)
A. assertIs(a,b)
A. assertIn(a,b)
(1)
A. if numerator is None or denominator is None:
A. if numerator is None and denominator is None:
A. if numerator = None or denominator = None:
A. if numerator = None and denominator = None:
(2)
A. elif denominator == 0:
A. elif denominator = 0:
A. elif denominator != 0:
A. elif denominator in 0:
上方程式碼 def safe_root(a, b):
下方程式碼 answer = a ** (1 / b)
if a>= 0:
if a%2==0:
else:
elif:
上方程式碼 answer = a ** (1 / b)
下下方程式碼 answer = "Result is an imaginary number"
if a>= 0:
if a%2==0:
else:
elif:
上上方程式碼 answer = a ** (1 / b)
下方程式碼 answer = "Result is an imaginary number"
if a>= 0:
if a%2==0:
else:
elif:
上方程式碼 answer = "Result is an imaginary number"
下方程式碼 answer = -(-a) ** (1 / b)
if a>= 0:
if a%2==0:
else:
elif:
計算以下的 Python 數學運算式
(5 (1 + 2) * 2 – 3 + 4 / 2)
結果為何?
A. 5
A. 8
A. 44
A. 22
請問第一個print後面顯示的內容為何?
True
False
請問第二個print後面顯示的內容為何?
True
False
請問第三個print後面顯示的內容為何?
True
False
請問第四個print後面顯示的內容為何?
True
False
某間銀行要將他們舊有的銀行交易程式碼轉至Python。該銀行雇用您來記錄已移轉的程式碼。
請問哪個文件記錄語法是正確的?
def get_balance():
/* Returns the current balance of the bank account */ return balance
// Returns the current balance of the bank account def get_balance():
return balance
‘Returns the current balance of the bank account def get_balance():
return balance
def get_balance():
# Returns the current balance of the bank account return balance
請問您應該在第03行使用哪個程式碼片段?
while (index<10):
while [index<10]
while (index<5)
while [index<5]
請問您應該在第06行使用哪個程式碼片段?
if numbers[index]==6
if numbers[index]==6:
if numbers(index)=6:
if numbers(index)!=6
請問第二個print後面顯示的內容為何?
A. Config1
A. Config1Config2
A. Config2
A. Config2Config1
請問第三個print後面顯示的內容為何?
A. Config1
A. Config1Config2
A. Config2
A. Config2Config1
你設計了一個數學運算的 Python 程式,程式碼如下:
01 a = 21
02 b = 5
03 print(a / b)
04 print(a // b)
05 print(a % b)
下列每個數學運算式的結果依序是?
A. 4.2, 4, 1
A. 4, 4, 4
A. 1, 4, 4.2
1. 請問哪些字元代表單行文件字串的開頭和結尾?
A. 單引號(')
A. 雙引號(")
A. 兩個雙引號("")
A. 三個雙引號(""")
1. 在記錄函式時,文件字串的標準位置在哪裡?
A. 在程式檔案的開頭
A. 在函式上方
A. 緊湊在函式檔案後面
A. 在函式的結尾
A. 在程式檔案的結尾
1. 請檢閱下列函式:
def cube(n):
""" Returns the cube of number n """
return n*n*n
請問哪個命令可列印文件字串?
A. print( doc )v
A. print(cube(doc))
A. print(cube. doc )
A. print(cube(docstring))
b=
(a)
答案位置
process()
(a)
答案位置
logError()
(a)
答案位置
displayResult()
(a)
請問哪兩個函式呼叫是正確的?(請選擇2個答案。)請注意:每一個答對的項目都能獲得部分分數。
name = input("What is your name?") grade=0
while grade not in (1,2,3,4,5,6):
grade = int(input("What grade are you in (1-6)?")) roomAssignment(name,year=grade)
name = input("What is your name?") grade=0
while grade not in (1,2,3,4,5,6):
grade = int(input("What grade are you in (1-6)?")) roomAssignment(student,year)
roomAssignment("Sherlock Sassafrass",4)
roomAssignment(year=6,name="Minnie George")
此函式會傳回一個值。
正確
錯誤
第14和17行的函式呼叫無效。
正確
錯誤
第16和18行的函式呼叫會產生錯誤。
正確
錯誤
type(+1E10)
(a)
type(5.0)
(a)
type("True")
(a)
type(False)
(a)
第02行會造成執行階段錯誤。
正確
錯誤
第06行會造成執行階段錯誤。
正確
錯誤
eval函式應該用於第03和04行。
正確
錯誤
為了符合需求,您必須將第01行變更為:
def increment_score(score, bonus, points =1):
正確
錯誤
以預設值定義任何參數之後,右側的所有參數也必須使用預設值來定義。
正確
錯誤
如果您不變更第01行,而且僅使用兩個參數來呼叫此函式,第三個
參數的值將為None。
正確
錯誤
第03行也會修改在第06行宣告之變數points的值。
正確
錯誤
在下列的程式碼中:
slist = ['a', 'b', 'c', 'd', 'e', 'f'] print('f' in slist)
執行後會輸出列印的內容?
5
6
True
False
