Skip to content

lesson_8 #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions lesson_8_1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
"""
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)