# -----------------------凡事在成熟之前,都是有苦味的.---------------------------#
day 19
#项目经理
# class Base:
# def login(self):
# raise NotImplementedError("子类没有实现该方法") #报错.抛异常
#
#
# # 普通登录-->
# class Normal(Base):
# def login(self):
# print("普通登录")
#
# class Member(Base):
# def logon(self):
# print("吧务登录")
#
# class Admin(Base):
# def login(self):
# print("管理员登录")
#
# # 项目经理
# def ohmygod:
# pass
# ---------------------------------------------------------------------------------#
# from abc import ABCMeta, abstractmethod
#
#
# class Animal(metaclass=ABCMeta):
# @abstractmethod
# def chi(self): # 抽象类
# pass
#
#
# class Cat(Animal): # 子类
# def chi(self): # 子类给抽象类给出具体实现的对象,
# print("猫用爪子抓鱼吃")
#
#
# c = Cat()
# c.chi()
#
# a = Animal() # 报错 Animal类是抽象类 不能实例化对象
# a.chi()
# ---------------------------------------------------------------------------------#
#
# def cul(a, b):
# if (type(a) == int or type(a) == float) and (type(b) == int or type == float):
# return a + b
# else:
# raise Exception("输入不正确,请核查")
#
# # print(cul(1,5))
# # print(cul(1,"ttr"))
#
# try:
# cul(1,"ttr")
# except:
# print("格式不对")
# else:
# print("OK")
# finally:
# print("再次输入")
# ---------------------------------------------------------------------------------#
# class AgeExcption(Exception):
# pass
#
#
# class Person:
# def __init__(self, age, country):
# self.age = age
# self.country = country
#
# def wacth_movie(self):
# if self.age >= 18:
# print("你成年啦,可以看小电影啦")
# else:
# print("未成年,好好学习吧!")
#
#
# try:
# p1 = Person(25, "China")
# p1.wacth_movie()
#
# p2 = Person(17, "American")
# p2.wacth_movie()
#
# except AgeExcption as exxxx:
# print("小盆友,你还小.")
#
# except Exception as e:
# print("反正进不去")
# -------------------------------[作业.txt]-------------------------------------#
# 1. 整理今日内容, 写博客
'''
1. 约束(1. 抛出异常, 2. 写抽象类)(难点, 重点)
1. 抛出异常; NotImplementedError
2. 抽象类
from abc import ABCMeta, abstractmethod
class Base(metaclass = ABCMeta): 抽象类
@abstractmethod
def 方法(self):pass
class Foo(Base): 子类必须重写父类中的抽象方法
def 方法(self):
pass
一个类包含类抽象方法. 这个类一定是抽象类
抽象类中可以有正常的方法
抽象类中如果有抽象方法. 这个类将不能创建对象
接口: 类中都是抽象方法
2. 异常处理
try:
except Error as e:
except....
else:
finally:
收尾
import traceback
try:
# 尝试执行的代码
except Exception as e:
# 除了错之后要做什么
traceback.format_exc() # 获取堆栈信息(错误信息)
3. 日志处理
logging
critical
error(最多)
wraning
info
debug
预习:
多继承. 深度递归遍历(经典类)
继承 MRO c3算法 (难)
super()
面向对象的内容过一遍
'''
# ---------------------------------------------------------------------------------#
# 2. 将课上代码补全. 对于每种用户给出不同的文件作为用户信息的保存.
# 贴吧
# 项目经理(级别高一点儿)
#
# class Base:
# def login(self): # 强制子类做xxxx事
# raise NotImplementedError("子类没有实现该方法")
# # 子类没有实现该方法" # 报错. 抛异常
#
#
# # 1. 普通账号 --> 翔哥
# class Normal(Base):
# def login(self): # 读取普通账户.txt文件
# print("普通账号的登录")
#
#
# # 2. 吧务 - > 强哥
# class Member(Base):
# def login(self): # 读取普通账户.txt文件
# print("吧务的登录")
#
#
# # 3. 百度员工 -> 明哥
# class Admin(Base):
# def login(self): # 读取普通账户.txt文件
# print("管理员的登录")
#
#
# # 项目经理
# def wodetian(obj):
# obj.login()
#
#
# n = Normal()
# wodetian(n)
#
# m = Member
# wodetian(m)
#
# a = Admin()
# wodetian(a)
# ---------------------------------------------------------------------------------#
# 3. 在第二题的做完的基础上去优化代码. 重构代码. 想出更加合理
# 更加简洁的处理方案(升级题)
# ---------------------------------------------------------------------------------#
# 4. 完成植物大战僵尸代码编写. 要求:
# 1. 创建植物类, 植物拥有名称, 血量, 攻击力
# class Plant:
# def __init__(self, name, hp, atk):
# self.name = name
# self.hp = hp
# self.atk = atk
#
# def penpen(self, js):
# js.less_hp -= self.atk
#
# def less_hp(self):
# pass
#
#
# # 2. 创建僵尸类, 僵尸拥有名称, 血量, 攻击力
#
# class Zom:
# def __init__(self, name, hp, atk):
# self.name = name
# self.hp = hp
# self.atk = atk
#
# def kenken(self, Plant):
# Plant.less_hp()
#
# def less_hp(self):
# pass
# 3. 僵尸和植物都可以互相的攻击.
# p = Plant("小葵花", 100, 20)
# z = Zom("僵尸叔叔", 100, 30)
#
# # 4. 创建出僵尸和植物. 让植物去攻击僵尸两次. 僵尸反
# # 过来攻击植物三次
#
# p.penpen(z)
# z.less_hp()
# p.penpen()
# z.less_hp()
#
# z.kenken()
# p.less_hp()
# z.kenken()
# p.less_hp()
# z.kenken()
# p.less_hp()
#
#
# # 5.尽可能减少代码的编写.给出最优解决方案(代码优化)
# # ---------------------------------------------------------------------------------#
# # 5. 完成安装空调功能, 具体属性由自己进行设计
# # 1. 创建班级类.
# class Cluss:
# def __init__(self, cluss, grade):
# self.cluss = cluss
# self.grade = grade
#
#
# # 2. 创建空调类
# class Air_conditioner:
# pass
#
#
# # 3. 创建空调师傅类
# class upfitter: # upfitter 装修工
# def zhuangkt(self):
# print("z")
#
#
# # 4. 空调师傅可以给xxx班级安装xxx空调
# c = Cluss("二班", "六年级")
# k = Air_conditioner
# u = upfitter
# u.zhuangkt()
# ---------------------------------------------------------------------------------#
# 6. 编写一个ATM程序. 功能和属性自行设计. (升级题)
# class ATM:
# def tuqian(self):
# pass
#
#
# class Person:
# def quqian(self):
# pass
#
#
# class display_money:
# def check_money(self):
# pass
#
#
# Atm = ATM()
# xiaohua = Person()
# ck = display_money
# ---------------------------------------------------------------------------------#
# 7. 算法题. 青蛙跳井. 青蛙掉井里了.井深20米 每个白天往上跳5
# 米, 晚上往下滑3米, 问青蛙几天可以从井里出来. (升级题, 做完
# 上面的题,预习和复习都OK了再想这个)
n = int(input("井深多少米?-->"))
count = 1
while 1:
if n <= 5:
print(count)
break
elif 2 * count + 5 <= n:
count+=1
print(count)
break
elif 2 * count + 5 > n:
count += 1
print(count)
break
# ---------------------------------------------------------------------------------#
'''
7. 明日默写:
1. 什么是类. 什么是对象
2. 类的成员
3. 函数中 * 和** 分别是用来做什么的?
4. 面向对象的三个特征.
'''