zoukankan      html  css  js  c++  java
  • 9-1 餐馆/ 9-2 三家餐馆/ 9-3 用户

    1. 动手试一试

     2. 代码

    class Restaurant():
        def __init__(self, restaurant_name, cuisine_type):
            self.restaurant_name = restaurant_name
            self.cuisine_type = cuisine_type
    
        def describle_restaurant(self):
            print("This is " + self.restaurant_name.title(),
                  "
    It have " + str(self.cuisine_type) + " pieces of foods.")
    
        def open_restaurant(self):
            print("Now is opening...")
    
    restaurant = Restaurant('Luckin', 54)   # 创建restaurant实例
    restaurant.describle_restaurant()   # 打印restaurant 属性
    restaurant.open_restaurant()    # 打印restaurant另一个属性
    print("-----------------------------------------------------------")
    
    
    restaurant1 = Restaurant('Sweet center', 108 )
    restaurant2 = Restaurant("KFC", 36)
    restaurant3 = Restaurant('Xiangtianxia', 18 )
    
    restaurant1.describle_restaurant()
    restaurant2.describle_restaurant()
    restaurant3.describle_restaurant()
    print("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@")
    
    class User():   # 创建User类
        def __init__(self, first_name, last_name, age, address, phone): # 属性
            self.first_name = first_name
            self.last_name = last_name
            self.age = age
            self.address = address
            self.phone = phone
    
        def describe_user(self):    # 方法
            print(self.first_name,
                  self.last_name,
                  self.age,
                  self.address,
                  self.phone)
    
        def greet_user(self):   # 方法
            print("How beautiful name " + self.last_name + self.last_name,
                  "
     too young, too simple", "your homeland " + self.address
                  + " is a warm place, ", "could you tell me your contact?")
    
    user1 = User('Mike', 'Jhon', 28 ,'Anhui', 13141161718)  # 实例化
    user2 = User('Kevin', 'Durant', 30, 'Shanghai', 1213141516)
    user3 = User('Alex', 'Li', 24, 'Beijing', 1618191714)
    
    user1.describe_user()   # 调用方法
    user2.describe_user()
    user3.describe_user()
    
    user1.greet_user()  # 调用方法
    user2.greet_user()
    user3.greet_user()
    

      3. 执行结果

    This is Luckin 
    It have 54 pieces of foods.
    Now is opening...
    -----------------------------------------------------------
    This is Sweet Center 
    It have 108 pieces of foods.
    This is Kfc 
    It have 36 pieces of foods.
    This is Xiangtianxia 
    It have 18 pieces of foods.
    @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
    Mike Jhon 28 Anhui 13141161718
    Kevin Durant 30 Shanghai 1213141516
    Alex Li 24 Beijing 1618191714
    How beautiful name JhonJhon 
     too young, too simple your homeland Anhui is a warm place,  could you tell me your contact?
    How beautiful name DurantDurant 
     too young, too simple your homeland Shanghai is a warm place,  could you tell me your contact?
    How beautiful name LiLi 
     too young, too simple your homeland Beijing is a warm place,  could you tell me your contact?
    
    Process finished with exit code 0
    

      

  • 相关阅读:
    vue mock数据设置
    vue 的全局拦截器
    vue-resource基础介绍
    快速排序
    Node 中的 stream (流)
    v8垃圾回收和js垃圾回收机制
    Node内存限制与垃圾回收
    ReactNative http网络通讯
    luogu1829 [国家集训队]Crash的数字表格
    luogu2870 [USACO07DEC]最佳牛线,黄金Best Cow Line, Gold
  • 原文地址:https://www.cnblogs.com/kevin-hou1991/p/14786592.html
Copyright © 2011-2022 走看看