2021-2022-1 20211418 《信息安全专业导论》第八周学习总结

作业信息

[2021-2022-1信息安全专业导论](https://edu.cnblogs.com/campus/besti/2021-2022-1fois)
[2021-2022-1信息安全专业导论第八周作业](https://www.cnblogs.com/rocedu/p/9577842.html#WEEK08)

教材学习内容总结

  1. 阅读《计算机科学概论》第9章(面向对象设计与高级程序语言设计),了解了面向对象方法,翻译过程及其工具,两种程序设计语言范型,高级程序设计语言和面向对象语言的功能性等内容,并学习了过程设计和面向对象设计的区别。
  2. 阅读《看漫画学Python》第9、10章(类与对象、异常处理),了解了面向对象、定义类、创建对象、类的成员、封装性、继承性、多态性、除零异常、捕获异常、finally代码块、自定义异常等内容。

教材学习中的问题和解决过程

本周暂无

代码调试过程中的问题和解决过程

问题1: 有一个代码照着书打,没有发现问题,但结果无法运行出来
问题1解决方案:在云班课上与同学讨论,得知是缩进出了问题,修改后就可以正常运行了。
问题2:9.7.2最后一个代码打完后正常运行但是不输出结果
问题2解决方案:经过对比教材和我的代码,发现我漏打了一个括号,导致没有引用

代码托管

class Car(object):
pass
car = Car()

class Dog:
def init(self,name,age):
self.name = name
self.age = age

d = Dog('Ball',2)
print("Our dog's name is {0},and it is {1} years old.".format(d.name,d.age))

class Dog:
def init(self,name,age,sex = 'Male'):
self.name = name
self.age = age
self.sex = sex

d1 = Dog('Ball',2)
d2 = Dog('Haha',1,'Male')
d3 = Dog(name='Mop',sex = 'Male',age = 3)
print("Our dog's name is {0},and it is {1} years old.".format(d1.name,d1.age,d1.sex))
print("Our dog's name is {0},and it is {1} years old.".format(d2.name,d2.age,d2.sex))
print("Our dog's name is {0},and it is {1} years old.".format(d3.name,d3.age,d3.sex))

class Account:
interest_rate = 0.0568

def __init__(self,owner,amount):
    self.owner = owner
    self.amount = amount

account = Account('Tony',800000.0)

print('Account name:{0}'.format(account.owner))
print('Account amount:{0}'.format(account.amount))
print('Interest rate:{0}'.format(Account.interest_rate))

class Account:
interest_rate = 0.0668

def __init__(self,owner,amount):
    self.owner = owner
    self.amount = amount
    
@classmethod
def interest_by(cls,amt):
        return cls.interest_rate * amt

interest = Account.interest_by(12000.0)
print('Calculate the interest:{0:.4f}'.format(interest))

class Account:
__interest_rate = 0.0568

def __init__(self,owner,amount):
    self.owner = owner
    self.__amount = amount

def desc(self):
print ("{0}amount:{1}interest rate:{2}.".format(self.owner,self.__amount,Account.__interest_rate))

account = Account('Tony',800000.0)

print('Account name:{0}'.format(account.owner))
print('Account amount:{0}'.format(account.amount))
print('Interest rate:{0}'.format(Account.interest_rate))

class Dog:

def __init__(self,name,age,sex = 'female'):
    self.name = name
    self.__age = age
    
def run(self):
    print("{} is running...".format(self.name))
    
def get_age(self):
    return self.__age

def set_age(self,age):
    self.__age = age

dog = Dog('Ball',2)
print("dog's age:{}".format(dog.get_age()))
dog.set_age(3)
print("the dog's age after correction:{}".format(dog.get_age()))

class Dog:

def __init__(self,name,age,sex = 'female'):
    self.name = name
    self.__age = age
    
def run(self):
    print("{} is running...".format(self.name))
    
@property
def age(self):
    return self.__age
@age.setter
def age(self,age):
    self.__age = age

dog = Dog('Ball',2)
print("dog's age:{}".format(dog.age))
dog.age = 3
print("the dog's age after correction:{}".format(dog.age))

class Animal:

def __init__(self,name):
    self.name = name
    
def show_info(self):
    return "Animal's name: {0}".format(self.name)

def move(self):
    print("Move ...")

class Cat(Animal):

def __init__(self,name,age):
    super().__init__(name)
    self.age = age

cat = Cat('Tom',2)
cat.move()
print(cat.show_info())

class Horse:
def init(self,name):
self.name = name

def show_info(self):
    return ("the horse's name: {0}".format(self.name))

def run(self):
    print("the horse runs...")

class Donkey:
def init(self,name):
self.name = name

def show_infp(self):
    return "the donkey's name:{0}".format(self.name)

def run(self):
    print("the donkey runs...")
    
def roll(self):
        print("the donkey rolls...")

class Mule (Horse,Donkey):

def __init__(self,name,age):
    super().__init__(name)
    self.age = age

m = Mule('Polly the Mule',1)
m.run()
m.roll()
print(m.show_info())

class Horse:
def init(self,name):
self.name = name

def show_info(self):
    return "the horse's name: {0}".format(self.name)

def run(self):
    print("the horse runs...")

class Donkey:
def init(self,name):
self.name = name

def show_init(self):
    return "the donkey's name:{0}".format(self.name)

def run(self):
    print("the donkey runs...")
    
def roll(self):
        print("the donkey rolls...")

class Mule (Horse,Donkey):

def __init__(self,name,age):
    super().__init__(name)
    self.age = age
    
def show_info(self):
    return "Mule:{0},{1} years old".format(self.name,self.age)

m = Mule('Polly the Mule',1)
m.run()
m.roll()
print(m.show_info())

class Animal:
def speak(self):
print("An animal is crying but we don't know what it is!")

class Dog(Animal):
def speak(self):
print("Puppy: WOOF...")

class Cat(Animal):
def speak(self):
print("Kitten:MEOW...")

an1 = Dog()
an2 = Cat()
an1.speak()
an2.speak()

def start(obj):
obj.speak()

class Animal:
def speak(self):
print("An animal is crying but we don't know what it is!")

class Dog(Animal):
def speak(self):
print("Puppy: WOOF...")

class Cat(Animal):
def speak(self):
print("Kitten:MEOW...")

class Car:
def speak(self):
print('Car:BEEP...')

start(Dog())
start(Cat())
start(Car())

i = input('Please enter a number: ')
n = 8888
try:
result = n / int(i)
print(result)
print('{0} divided by {1} is {2}'.format(n,i,result))
except:
print('The number cannot be divided by zero,errpr: {}'.format(e))

i = input('Please enter a number: ')
n = 8888
try:
result = n / int(i)
print(result)
print('{0} divided by {1} is {2}'.format(n,i,result))
except ZeroDivisionError as e:
print('The number cannot be divided by zero,errpr: {}'.format(e))
except ValueError as e:
print('The number input is invalid,error:{}'.format(e))

i = input('Please enter a number: ')
n = 8888
try:
result = n / int(i)
print(result)
print('{0} divided by {1} is {2}'.format(n,i,result))
except (ZeroDivisionError,ValueError) as e:
print('Error: {}'.format(e))

i = input('Please enter a number: ')
n = 8888

try:
i2 = int(i)
try:
result = n/12
print('{0} divided by {1} is {2}'.format(n,i2,result))

except ZeroDivisionError as e:
    print('The number cannot be divided by zero,errpr: {}'.format(e))

except ValueError as e:
print('The number input is invalid,error:{}'.format(e))

i = input('Please enter a number: ')
n = 8888

try:
result = n/int(i)
print(result)
print('{0} divided by {1} is {2}'.format(n,i,result))
except ZeroDivisionError as e:
print('The number cannot be divided by zero,errpr: {}'.format(e))
except ValueError as e:
print('The number input is invalid,error:{}'.format(e))
finally:
print("Resources released...")

class ZhijieketangExcepton(Exception):
def init(self,message):
super().init(message)

class ZhijieketangExcepton(Exception):
def init(self,message):
super().init(message)

i = input('Please enter a number: ')
n = 8888
try:
result = n / int(i)
print(result)
print('{0} divided by {1} is {2}'.format(n,i,result))
except ZeroDivisionError as e:
raise ZhijieketangExcepton("Can't be divided by zero.")
except ValueError as e:
raise ZhijieketangExcepton("Invalid number input.")

上周考试错题总结

暂无。

其他

本周学习任务还是比较重的,仍需更多时间巩固消化。

学习进度条

| | 代码行数(新增/累积)| 博客量(新增/累积)|学习时间(新增/累积)|重要成长|
| 第一周 | 200/200 | 2/2 | 20/20 | |
| 第二周 | 200/400 | 2/4 | 20/40 | |
| 第三周 | 200/600 | 2/6 | 20/60 | |
| 第四周 | 200/800 | 2/8 | 20/80 | |
| 第五周 | 200/1000 | 2/10 | 20/100 | |
| 第六周 | 200/1200 | 1/11 | 20/120 | |
| 第七周 | 200/1400 | 1/12 | 20/140 | |
| 第八周 | 200/1600 | 1/13 | 20/160 | |
|

参考资料

《计算机科学概论》《看漫画学Python》

 posted on 2021-11-13 15:45  20211418  阅读(41)  评论(0编辑  收藏  举报