#coding:gbk
class User:
	def __init__(self,first_name,last_name):
		self.first_name = first_name
		self.last_name = last_name
		self.login_attempts = 0
		
		
	def describe_user(self):
		fullname = self.first_name.title()+' '+self.last_name.title()
		return fullname.title()
		
	def greet_user(self):		
		print('Hi ,are u ok ? ') 
	
	def increment_login_attempts(self):
		self.login_attempts += 1
		return self.login_attempts
		
	def reset_login_attempts(self):
		self.login_attempts = 0
		return self.login_attempts
i = User('ng','young')
print(i.describe_user())

i.greet_user()

i.increment_login_attempts()
i.increment_login_attempts()
i.increment_login_attempts()
print(i.increment_login_attempts())#这里调用的是函数,所以函数下面需要return,否则没有返回值读取不了结果
print("  Login attempts: " + str(i.login_attempts))#这里直接调用的是login_attempts属性,所以不需要返回值
print(i.reset_login_attempts())


最后修改:2022 年 12 月 05 日
如果觉得我的文章对你有用,请随意赞赏