From f51153f7d905d1dc3f1b66324a53ca3dbda6247b Mon Sep 17 00:00:00 2001 From: Rudia Moon Date: Thu, 28 Jun 2018 19:55:56 +0900 Subject: [PATCH 1/2] Create validating_inputs_rudia.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 코딩 트레이닝 by 브라이언호건 27번문제 --- .../validating_inputs_rudia.py | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 pythontraning/validating_inputs/validating_inputs_rudia.py diff --git a/pythontraning/validating_inputs/validating_inputs_rudia.py b/pythontraning/validating_inputs/validating_inputs_rudia.py new file mode 100644 index 0000000..3655b55 --- /dev/null +++ b/pythontraning/validating_inputs/validating_inputs_rudia.py @@ -0,0 +1,46 @@ +import re + + +class inputVlaueCheck(object): + + def __init__(self): + pass + + def check_value_name(self, label, answer): + if answer is '': + print("The "+label+" name must be filled in") + elif len(answer) == 1: + print("\""+answer+"\" is not a valid "+label+ " name. It is too short.") + else: + pass + + def input_name(self, label): + a = input("Enter the "+label+" name:") + self.check_value_name(label, a) + + def input_zip_code(self): + answer = input("Enter the ZIP code:") + p = re.compile('^[0-9]*$') + m = p.match(answer) + if m: + pass + else: + print('The ZIP code must be numeric:' + answer) + + def input_employee_id(self): + answer = input("Enter the Employee ID:") + p = re.compile('([a-zA-Z]{1,2})\-([0-9]{4})') + m = p.match(answer) + if m: + pass + else: + print(answer+' is not a valid ID') + + +class excute_init(object): + if __name__ == "__main__": + inputVal = inputVlaueCheck() + inputVal.input_name("first") + inputVal.input_name("last") + inputVal.input_zip_code() + inputVal.input_employee_id() From 75c19872760ca15ec0c997eedba2df8bc28ba20f Mon Sep 17 00:00:00 2001 From: Rudia Moon Date: Fri, 6 Jul 2018 00:26:49 +0900 Subject: [PATCH 2/2] Update validating_inputs_rudia.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - input에서 enter로 메소드이름 컨벤션 - else remove --- .../validating_inputs_rudia.py | 25 ++++++++----------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/pythontraning/validating_inputs/validating_inputs_rudia.py b/pythontraning/validating_inputs/validating_inputs_rudia.py index 3655b55..02a636a 100644 --- a/pythontraning/validating_inputs/validating_inputs_rudia.py +++ b/pythontraning/validating_inputs/validating_inputs_rudia.py @@ -11,36 +11,31 @@ def check_value_name(self, label, answer): print("The "+label+" name must be filled in") elif len(answer) == 1: print("\""+answer+"\" is not a valid "+label+ " name. It is too short.") - else: - pass - def input_name(self, label): + def enter_name(self, label): a = input("Enter the "+label+" name:") self.check_value_name(label, a) - def input_zip_code(self): + def enter_zip_code(self): answer = input("Enter the ZIP code:") p = re.compile('^[0-9]*$') m = p.match(answer) - if m: - pass - else: + if not m: print('The ZIP code must be numeric:' + answer) - def input_employee_id(self): + def enter_employee_id(self): answer = input("Enter the Employee ID:") p = re.compile('([a-zA-Z]{1,2})\-([0-9]{4})') m = p.match(answer) - if m: - pass - else: + if not m: print(answer+' is not a valid ID') class excute_init(object): if __name__ == "__main__": inputVal = inputVlaueCheck() - inputVal.input_name("first") - inputVal.input_name("last") - inputVal.input_zip_code() - inputVal.input_employee_id() + inputVal.enter_name("first") + inputVal.enter_name("last") + inputVal.enter_zip_code() + inputVal.enter_employee_id() +