習題41 學習物件導向術語

2021-08-30 10:53:51 字數 1753 閱讀 5091

import random

from urllib.request import urlopen

import sys

word_url = ""

words =

phrases =

# do they want to drill pharases first

if len (sys.argv) == 2 and sys.argv[1] == "english":

# phrase_first = true

else:

phrase_first = false

# load up the words from the website

for word in urlopen(word_url).readlines():

def convert(snippet, phrase):

class_names = [w.capitalize() for w in

random.sample(words, snippet.count("%%%"))]

# 從words序列中抽取帶'###'的字串,數量是片段裡面含有'###'的數量並把第乙個字母變大寫,後面變小些(也就是隨機抽取類)

other_names = random.sample(words, snippet.count("***"))

results =

param_names =

for i in range(0, snippet.count("@@@")):

param_count = random.randint(1,3)

random.sample(words, param_count)))

for sentence in snippet, phrase:

result = sentence[:]

# 複製列表

# fake class names

for word in class_names:

result = result.replace("%%%", word, 1)

# fake other names

for word in other_names:

result = result.replace("***", word, 1)

# fake parameter lists

for word in param_names:

result = result.replace("@@@", word, 1)

return results

# keep going until they hit ctrl-d

try:

while true:

snippets = list(phrases.keys())

random.shuffle(snippets)

for snippet in snippets:

phrase = phrases[snippet]

question, answer = convert(snippet, phrase)

if phrase_first:

question, answer = answer, question

print(question)

input("> ")

print(f"answer: \n\n")

except eoferror:

print("\nbye")

看不懂,日後再看,,

習題41 學習物件導向術語

import random 匯入random庫 from urllib import urlopen 從urllib中匯入urlopen import sys 匯入sys word url words phrases do they want to drill phrases first phras...

學習物件導向之物件導向的術語

類類作為設計藍圖來建立物件的 段,它描述了物件的特徵 該物件具有什麼樣的屬性,怎樣使用物件完成一些任務,他對事件進行怎樣的響應等!物件物件是類的乙個例項,通常通過呼叫類的乙個建構函式來建立它!方法方法是在類中定義的函式,一般而言,乙個方法描述了物件可以執行的乙個操作www.cppcns.com!屬性...

物件導向程式設計之術語

術語 含義屬性 一小段資訊,例如顏色 高度或重量,描述物件的乙個特性 字段物件內部的指定值 操作屬於物件的一段 方法操作的同義詞 訊息從乙個物件傳送到另乙個物件的請求 呼叫執行操作,以響應訊息 執行呼叫的同義詞 關聯兩個物件之間的直接或間接連線 聚合強關聯,隱含著某種部分 一體層次結構 復合強聚合,...