generated from ISUCT/Algorithm_2023
-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
49 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
class Cat(): | ||
__age = 0 | ||
__name = "" | ||
__breed = "" | ||
|
||
def __init__(self, age, name, breed): | ||
self.age = age | ||
self.__name = name | ||
self.__breed = breed | ||
|
||
@property | ||
def age(self) -> int: | ||
return self.__age | ||
|
||
@age.setter | ||
def age(self, age): | ||
assert (age >= 0 and age <= 25), "Invalid age" | ||
self.__age = age | ||
|
||
@property | ||
def breed(self) -> str: | ||
return self.__breed | ||
|
||
@property | ||
def name(self) -> str: | ||
return self.__name | ||
|
||
@name.setter | ||
def name(self, name): | ||
self.__name = name | ||
|
||
def petTheCat(self): | ||
print("Cat {0} says meow\n".format(self.__name)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,18 @@ | ||
def summ(a: int, b: int) -> int: | ||
return a + b | ||
|
||
from lab6 import cat | ||
|
||
if __name__ == "__main__": | ||
print("Hello world") | ||
print(summ(3, 4)) | ||
cat1 = cat.Cat(6, "Tiger", "Siamese") | ||
cat2 = cat.Cat(9, "No name", "unknown") | ||
|
||
cat1.age = 3 | ||
|
||
cat2.name = "Marshal" | ||
cat1.name = "Luna" | ||
|
||
print("Cat's age is {0}".format(cat1.age)) | ||
print("Its name is {0}".format(cat1.name)) | ||
cat1.petTheCat() | ||
|
||
print("Another cat's age is {0}".format(cat2.age)) | ||
print("Its breed is {0}".format(cat2.breed)) | ||
cat2.petTheCat() |