Last active
August 8, 2019 13:45
-
-
Save lawrencechen0921/85841776f99b503040b59e7f6bb966e0 to your computer and use it in GitHub Desktop.
try-except-as-else pwd example-python 與自訂例外類別
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
Class PwdException(Exception): | |
def _init_(self,pwd,len): | |
super(). _init_(self) #呼叫基礎類別 | |
self.pwd = pwd | |
self.len = len | |
try: | |
pwd = input('請輸入密碼,長度至少為8個字元') | |
if len(pwd) < 8: | |
raise PwdException(pwd,len(pwd)) | |
except EOFError: | |
print('輸入EOF') | |
except.PwdException as pex: | |
print('密碼',pex.pwd,'長度為',pex.len,'密碼長度不足') | |
else: | |
print('輸入長度為',pwd) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment