第五周作业(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()

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

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()

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

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")

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

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()

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

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")

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