SYSU Python第五周作业

#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(self.restaurant_name,' ',self.cuisine_type)
    def open_restaurant(self):
        print("The restaurant is open")

a=Restaurant("A","type A")
print(a.restaurant_name)
print(a.cuisine_type)
a.describe_restaurant()
a.open_restaurant()

#9.3
class User():
    def __init__(self,first_name,last_name):
        self.first_name=first_name
        self.last_name=last_name
    def describe_user(self):
        print(self.first_name,' ',self.last_name)
    def greet_user(self):
        print("Hello,",self.first_name)

a=User('K','L')
a.greet_user()
#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(self.restaurant_name,' ',self.cuisine_type)
    def open_restaurant(self):
        print("The restaurant is open")
    def set_number_served(self,num):
        self.number_served=num
    def increase_number_served(self,num):
        self.number_served+=num
#9.6
class IceCreamStand(Restaurant):
    def __init__(self, restaurant_name, cuisine_type):
        super().__init__(restaurant_name, cuisine_type)
        self.flavors=['aa','bb','cc']
    def showflavors(self):
        print(self.flavors)
stand=IceCreamStand('a','b')
stand.showflavors()
    
#10.1
with open('Learning_python.txt') as file_object:
    contents=file_object.read()
    print(contents)

with open('Learning_python.txt') as file_object:
    for line in file_object:
        print(line.rstrip())

with open('Learning_python.txt') as file_object:
    lines=file_object.readlines()
for line in lines:
    print(line.rstrip())
#10.2
with open('Learning_python.txt') as file_object:
    lines=file_object.readlines()
for line in lines:
    print(line.replace('python','C++').rstrip())
#10.3
name=input("Please enter your name: ")
with open('guest.txt','w') as file_object:
    file_object.write(name)
#10.4
flag=1
with open('guest_book.txt','w') as file_object:
    while flag:
        name=input("Please enter your name: ")
        c=input("continue? Y/N ")
        if c=='N':
           flag=0;    
        file_object.write(name)
        file_object.write('\n')
#10.5
valid=1
a=input("Please input the first number: ")
try:
    c=int(a)
except ValueError:
    print("Invalid input!")
    exit(1)

b=input("Please input the second number: ")
try:
    d=int(b)
except ValueError:
    print("Invalid input!")
    exit(1)

print(c+d)


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值