第五周作业(1)——高级编程技术

一. 第九章作业节选

9-1

class Restaurant():
def __init__(self, restaurant_name, cuisine_type):
self.restaurant_name = restaurant_name
self.cuisine_type = cuisine_type
def describe_restaurant(self):
print("restaurant_name: " + self.restaurant_name + ", " + "cuisine_type: " + self.cuisine_type + ".")
def open_restaurant(self):
print("This restaurant is opening now!")

restaurant = Restaurant("Qilixiang", "Sichuan cuisine")
print("The name of this restaurant: " + restaurant.restaurant_name + ", " + "cuisine type: " + restaurant.cuisine_type+ ".") 

restaurant.describe_restaurant()

restaurant.open_restaurant()


9-2

class Restaurant():
def __init__(self, restaurant_name, cuisine_type):
self.restaurant_name = restaurant_name
self.cuisine_type = cuisine_type
def describe_restaurant(self):
print("restaurant_name: " + self.restaurant_name + ", " + "cuisine_type: " + self.cuisine_type + ".")
def open_restaurant(self):
print("This restaurant is opening now!")

restaurant_1 = Restaurant("Qilixiang", "Sichuan cuisine")
restaurant_1.describe_restaurant()
restaurant_2 = Restaurant("Haochi", "Guangdong cuisine")
restaurant_2.describe_restaurant()
restaurant_3 = Restaurant("Gaojie", "Hunan cuisine")

restaurant_3.describe_restaurant()


9-3

class User():
def __init__(self, first_name, last_name, age, adrress):
self.first_name = first_name
self.last_name = last_name
self.age = age
self.adrress = adrress
def describe_user(self):
print("First_name:" + self.first_name + ", last_name: " + self.last_name + ", age: " + str(self.age) + ", adrress: " + self.adrress + ".")
def  greet_user(self):
print("Hello, " + self.first_name + " " + self.last_name + ".")

user1 = User('Zhu', 'Gaijie', 18, 'Shanxi')
user1.describe_user()
user1.greet_user()
print("\n")
user2 = User('Xu', 'Haichen', 17, 'Shanxi')
user2.describe_user()
user2.greet_user()
print("\n")
user3 = User('Xu', 'Yi', 16, 'Fujian')
user3.describe_user()
user3.greet_user()

print("\n")


9-4

class Restaurant():
def __init__(self, restaurant_name, cuisine_type):
self.restaurant_name = restaurant_name
self.cuisine_type = cuisine_type
self.number_served = 0
def describe_restaurant(self):
print("restaurant_name: " + self.restaurant_name + ", " + "cuisine_type: " + self.cuisine_type + ".")
print("number_served: " + str(self.number_served))
def open_restaurant(self):
print("This restaurant is opening now!")

restaurant = Restaurant("Qilixiang", "Sichuan cuisine")
restaurant.describe_restaurant()
restaurant.number_served = 23
restaurant.describe_restaurant()

9-5

class User():
def __init__(self, first_name, last_name, age, adrress, login_attempts):
self.first_name = first_name
self.last_name = last_name
self.age = age
self.adrress = adrress
self.login_attempts = login_attempts
def describe_user(self):
print("First_name:" + self.first_name + ", last_name: " + self.last_name + ", age: " + str(self.age) + ", adrress: " + self.adrress + ", login_attempts: " + str(self.login_attempts) + ".")
def  greet_user(self):
print("Hello, " + self.first_name + " " + self.last_name + ".")
def increment_login_attempts(self):
self.login_attempts = self.login_attempts + 1
print("login_attempts: " + str(self.login_attempts))
def reset_login_attempts(self):
self.login_attempts = 0
print("login_attempts: " + str(self.login_attempts))

user = User('Zhu', 'Gaijie', 18, 'Shanxi', 0)
user.describe_user()
user.increment_login_attempts()
user.increment_login_attempts()
user.increment_login_attempts()
user.reset_login_attempts()

print("\n")




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值