():"""使用者"""
def__init__
(self, first_name, last_name):
"""初始化姓名"""
self.first_name = first_name.title()
self.last_name = last_name.title()
defdescribe_user
(self):
"""輸出姓名"""
print('this is ' + self.first_name + ' ' + self.last_name + '.')
defgreet_user
(self):
"""問候"""
print("hello, " + self.first_name + '. nice to meet you!')
user = user("albert", "ye")
user.describe_user()
user.greet_user()
# 9-5
class
user
():"""使用者"""
def__init__
(self, first_name, last_name):
"""初始化姓名"""
self.first_name = first_name.title()
self.last_name = last_name.title()
self.login_attempts = 0
defdescribe_user
(self):
"""輸出姓名"""
print('this is ' + self.first_name + ' ' + self.last_name + '.')
defgreet_user
(self):
"""問候"""
print("hello, " + self.first_name + '. nice to meet you!')
defincrement_login_attempts
(self):
"""增加登陸嘗試次數"""
self.login_attempts += 1
defreset_login_attempts
(self):
"""重置登陸嘗試次數"""
self.login_attempts = 0
user = user("albert", "ye")
user.increment_login_attempts()
print(user.login_attempts)
user.increment_login_attempts()
print(user.login_attempts)
user.increment_login_attempts()
print(user.login_attempts)
user.reset_login_attempts()
print(user.login_attempts)
# 9-7
class
user
():"""使用者"""
def__init__
(self, first_name, last_name):
"""初始化姓名"""
self.first_name = first_name.title()
self.last_name = last_name.title()
self.login_attempts = 0
defdescribe_user
(self):
"""輸出姓名"""
print('this is ' + self.first_name + ' ' + self.last_name + '.')
defgreet_user
(self):
"""問候"""
print("hello, " + self.first_name + '. nice to meet you!')
defincrement_login_attempts
(self):
"""增加登陸嘗試次數"""
self.login_attempts += 1
defreset_login_attempts
(self):
"""重置登陸嘗試次數"""
self.login_attempts = 0
class
admin
(user):
"""管理員"""
def__init__
(self, first_name, last_name, privileges):
"""初始化管理員,許可權為乙個字串list"""
super().__init__(first_name, last_name)
self.privileges = privileges
defshow_privileges
(self):
"""輸出許可權"""
print(self.privileges)
admin = admin("albert", "ye",
["can add post", "can delete post", "can ban user"])
admin.show_privileges()
# 9-13
from collections import ordereddict
dict = ordereddict()
dict["def"] = "定義"
dict["int"] = "整數"
dict["class"] = "類"
for word, explanation in dict.items():
print("word" + ' "' + word + '" means ' + explanation)
print()
dict["int"] = "整數"
for word, explanation in dict.items():
print("word" + ' "' + word + '" means ' + explanation)
編寫寵物dog類python 第 9 章 類
物件導向程式設計是最有效的軟體編寫方法之一。在物件導向程式設計中,我們編寫表示現實世界中的事物和情景的類,並基於這些類來建立物件。編寫類時,我 們定義一大類物件都有的通用行為。基於類建立物件時,每個物件都自動具備這種通用行為,然後可根據需要賦予每個物件獨特的個性。使用物件導向程式設計可模擬 現實情景...
《python程式設計快速上手》第9章 作業9 8 3
本來想偷懶不做這題,感覺好麻煩,就上網找找答案。結果沒有滿意的,還是自己寫乙個吧。相較於一位網上同學的答案,此 亮點在 03d 和zip 函式的使用,還有任務拆分清晰。做了個把小時的,還算滿意,就作為第一篇部落格,激勵下自己繼續努力。如有錯誤,請指出以相互學習,多謝!python3 complete...
零基礎學習Python 作業 第9章
ch09 homework 0 下面的迴圈會列印多少次 i love fishc for i in range 0,10,2 print i love fishc?answer 5 次 1 下面的迴圈會列印多少次 i love fishc 1.for i in 5 2.print i love fi...