当前位置:   article > 正文

Python课程第八章练习

Python课程第八章练习

<code>这里写图片描述</code>


这里写代码片
class Restaurant():
def init(self, restaurant_name, cuisine_type):
self.name = restaurant_name
self.cuisine_type = cuisine_type

def describe_restaurant(self):
    print("Name:" + self.name)
    print("cuisine type:" + self.cuisine_type)

def open_restaurant(self):
    print("Welcome to our restaurant!")
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

a = Restaurant(‘A’, ‘Chicken’)
b = Restaurant(‘B’, ‘Mutton’)

print(a.name)
print(a.cuisine_type)
a.describe_restaurant()
a.open_restaurant()

print(b.name)
print(b.cuisine_type)
b.describe_restaurant()
b.open_restaurant()

class User():
def init(self, first_name, last_name):
self.first_name = first_name
self.last_name = last_name

def describe_user(self):
    print("User's name is " + self.first_name + ' ' + self.last_name)

def greet_user(self):
    print("Hello, I'm " + self.first_name + ' ' + self.last_name + '!')
  • 1
  • 2
  • 3
  • 4
  • 5

a = User(‘Allen’, ‘Walker’)
b = User(‘Tom’, ‘Sawyer’)

a.describe_user()
a.greet_user()

b.describe_user()
b.greet_user()

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/凡人多烦事01/article/detail/616880
推荐阅读
相关标签
  

闽ICP备14008679号