Today I try to write a English blog to review the knowledge which learning from the class #exercise 1 class Person: def __init__(self, fname, lname): self.firstname = fname self.lastname = lname def printname(self): print(self.firstname, self.lastname) class Student(Person): name='' def printname(self): return str(self.name) class Teacher(Person): def __init__(self, fname, lname,department): super().__init__(fname,lname) self.department = department def printname(self): print(self.firstname, self.lastname,self.department) x = Student("Bob", "Bobba") x.printname() y = Person("Bob", "Bobba") y.printname() z = Teacher("GEOGE","KENYA","wow") print(z.department) z.printname() #exercise 2 #use the try,except,else,finally to raise the exceptions try: x = 1 / 0 #error print(x) except Exception: print("An error occured") try: princesses = [ {"name": "Ariel", "age": 16, "prince": "Eric"}, {"name": "Jasmine", "age": 16, "prince": "Aladdin"}, {"name": "Rapunzel", "age": 18, "prince": "Flynn Rider"}, {"name": "Belle", "age": 17, "beast": "The Beast"}, {"name": "Mulan", "age": 16, "prince": "Li Shang"} ] except Exception as result: for princess in princesses: print("Princess {princess['name']} is {princess['age']} years old.") print("Her prince is {princess['prince']}") else: pass finally: print("These are the all of the royal's families") #exercise 3 #I want to know how the keys and words to order #If there haven't any word in the dictionary,how do the keys ordered a={"18","4","12"} def _print_people(b,c,d): print(b) print(c) print(d) print(a) print(*a) _print_people(20,40,60) _print_people(*a)
conclusion of my exercise 3 that If there only have keys in the dictionary, they are disordered,
thanks for reading