From 789772b49a3f42112d4f6269b3e1a5bab4328a3f Mon Sep 17 00:00:00 2001 From: Don Diamond Date: Tue, 29 Dec 2020 20:26:09 +0300 Subject: [PATCH 1/2] Create lesson_8_1.py init branch --- lesson_8_1.py | 1 + 1 file changed, 1 insertion(+) create mode 100644 lesson_8_1.py diff --git a/lesson_8_1.py b/lesson_8_1.py new file mode 100644 index 0000000..ba77549 --- /dev/null +++ b/lesson_8_1.py @@ -0,0 +1 @@ +print('__ok__') \ No newline at end of file From 01097f58a7f2fe32d421a2f0fe75811ddbddfedf Mon Sep 17 00:00:00 2001 From: Don Diamond Date: Tue, 29 Dec 2020 21:15:10 +0300 Subject: [PATCH 2/2] Update lesson_8_1.py --- lesson_8_1.py | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/lesson_8_1.py b/lesson_8_1.py index ba77549..a7437bb 100644 --- a/lesson_8_1.py +++ b/lesson_8_1.py @@ -1 +1,28 @@ -print('__ok__') \ No newline at end of file +""" +https://github.com/gitddpsm/PythonBasics/pull/8 +""" +class VinCodeError(Exception): + def __init__(self, txt): + self.txt = txt + + @classmethod + def vin_Validator(cls, vincode): + if not isinstance(vincode, str): + raise cls('Wrong vin type, need string') + elif len(vincode) < 10: + raise cls('Not correct vin length') + return vincode +class Car: + def __init__(self, name, vincode): + self.name = name + self.vincode = VinCodeError.vin_Validator(vincode) + +if __name__ == '__main__': + try: + car1 = Car('name1', '12') + except VinCodeError: + print('create a new car') + car1= Car('Name', 'dasd123afaf') + + print(car1.name) + print(car1.vincode)