1 问题
图
1
问题
9
−
5
图1~ 问题9-5
图
1
问题
9
−
5
2 代码及其输出
# 9-5
class User:
def __init__(self, first_name, last_name, login_attempts):
self.first_name = first_name
self.last_name = last_name
self.login_attempts = login_attempts
def describe_user(self):
print("user name is " + self.first_name + self.last_name)
def greet_user(self):
print("hello! " + self.first_name + self.last_name)
def increment_login_attempts(self):
self.login_attempts += 1
def reset_login_attempts(self):
self.login_attempts = 0
# Answer question 9-5!
# create two objects
u_1 = User("k", "t4ngw", 0)
# Calling 5 times!
for i in range(5):
u_1.increment_login_attempts()
print(u_1.login_attempts) # login_attempts = 5
# reset login_attempts!
u_1.reset_login_attempts()
print(u_1.login_attempts) # login_attempts = 0
# output
5
0
版权声明:本文为t4ngw原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。