class Restaurant():
def __init__(self,restaurant_name,cuisine_type):
self.name = restaurant_name
self.type = cuisine_type
def describe_restaurant(self):
print("Restaurant's name is " + self.name.title() )
print("Cuisine type is " + self.type.title())
def open_restaurant(self):
print('In operation')
my_restaurant = Restaurant('金拱门','快餐')
my_restaurant.describe_restaurant()
my_restaurant.open_restaurant()
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
class Restaurant():
def __init__(self,restaurant_name,cuisine_type):
self.name = restaurant_name
self.type = cuisine_type
def describe_restaurant(self):
print("Restaurant's name is " + self.name.title() )
print("Cuisine type is " + self.type.title())
def open_restaurant(self):
print('In operation')
my_restaurant1 = Restaurant('金拱门','快餐')
my_restaurant2 = Restaurant('银拱门','中餐')
my_restaurant3 = Restaurant('铜拱门','慢餐')
my_restaurant1.describe_restaurant()
my_restaurant2.describe_restaurant()
my_restaurant3.describe_restaurant()
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
class User():
def __init__(self,first_name,last_name):
self.first_name = first_name
self.last_name = last_name
def describe_user(self):
print("First name is " + self.first_name.title() )
print("Last name is " + self.last_name.title())
def greet_user(self):
full_name = self.first_name + ' ' + self.last_name
print('Hello ' + full_name.title())
user1 = User('ergou','yang')
user2 = User('qiqi','jiang')
user1.describe_user()
user1.greet_user()
user2.describe_user()
user2.greet_user()
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
class Restaurant():
def __init__(self,restaurant_name,cuisine_type):
self.name = restaurant_name
self.type = cuisine_type
self.number_served = 0
def describe_restaurant(self):
print("Restaurant's name is " + self.name.title() )
print("Cuisine type is " + self.type.title())
print('How many people have dinner in the restaurant? ' + str(self.number_served))
def open_restaurant(self):
print('In operation')
def set_number_served(self,people):
self.number_served = people
def increment_number_served(self,people):
self.number_served += people
restaurant = Restaurant('金拱门','快餐')
restaurant.describe_restaurant()
restaurant.open_restaurant()
restaurant.set_number_served(10)
restaurant.describe_restaurant()
restaurant.increment_number_served(3)
restaurant.describe_restaurant()
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
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):
print("First name is " + self.first_name.title() )
print("Last name is " + self.last_name.title())
def greet_user(self):
full_name = self.first_name + ' ' + self.last_name
print('Hello ' + full_name.title())
def increment_login_attempts(self):
self.login_attempts += 1
def reset_login_attempts(self):
self.login_attempts = 0
user1 = User('ergou','yang')
user1.describe_user()
user1.increment_login_attempts()
user1.greet_user()
user1.increment_login_attempts()
user1.increment_login_attempts()
print(user1.login_attempts)
user1.reset_login_attempts()
print(user1.login_attempts)
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
class Restaurant():
def __init__(self,restaurant_name,cuisine_type):
self.name = restaurant_name
self.type = cuisine_type
self.number_served = 0
def describe_restaurant(self):
print("Restaurant's name is " + self.name.title() )
print("Cuisine type is " + self.type.title())
print('How many people have dinner in the restaurant? ' + str(self.number_served))
def open_restaurant(self):
print('In operation')
def set_number_served(self,people):
self.number_served = people
def increment_number_served(self,people):
self.number_served += people
class IceCreamStand(Restaurant):
def __init__(self,restaurant_name,cuisine_type):
super().__init__(restaurant_name,cuisine_type)
self.flavors = ['apple','milk']
def show(self):
print(self.flavors)
restaurant = IceCreamStand('金拱门','快餐')
restaurant.describe_restaurant()
restaurant.show()
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
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):
print("First name is " + self.first_name.title() )
print("Last name is " + self.last_name.title())
def greet_user(self):
full_name = self.first_name + ' ' + self.last_name
print('Hello ' + full_name.title())
def increment_login_attempts(self):
self.login_attempts += 1
def reset_login_attempts(self):
self.login_attempts = 0
class Admin(User):
def __init__(self,first_name,last_name):
super().__init__(first_name,last_name)
self.privileges = ["can add post" ,"can delete post" ,"can ban user"]
def show_privileges(self):
print(self.privileges)
user = Admin('ergou','yang')
user.show_privileges()
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
class Privileges():
def __init__(self):
self.privileges = ["can add post" ,"can delete post" ,"can ban user"]
def show_privileges(self):
print(self.privileges)
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):
print("First name is " + self.first_name.title() )
print("Last name is " + self.last_name.title())
def greet_user(self):
full_name = self.first_name + ' ' + self.last_name
print('Hello ' + full_name.title())
def increment_login_attempts(self):
self.login_attempts += 1
def reset_login_attempts(self):
self.login_attempts = 0
class Admin(User):
def __init__(self,first_name,last_name):
super().__init__(first_name,last_name)
self.privileges = Privileges()
user = Admin('ergou','yang')
user.privileges.show_privileges()
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
#9-9 9-10 9-11 9-12
略
from collections import OrderedDict
favorite_languages = OrderedDict()
favorite_languages['jen'] = 'python'
favorite_languages['sarah'] = 'c'
favorite_languages['edward'] = 'ruby'
favorite_languages['phil'] = 'python'
for name, language in favorite_languages.items():
print(name.title() + "'s favorite language is " +
language.title() + ".")
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
from random import randint
class Die():
def __init__(self):
self.sides = 6
def roll_die(self):
x = randint(1, self.sides)
print(str(x))
die = Die()
for x in range(0,10):
die.roll_die()
die.sides = 10
for x in range(0,10):
die.roll_die()
die.sides = 20
for x in range(0,10):
die.roll_die()
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
...