import numpy as np
import re
isNum = False
while not isNum:
data = input("숫자를 입력하세요 (정수형 또는 고정소숫점 방식) ->")
if data == '':
print('잘못된 입력입니다.')
elif data[0] == ('-' or '+'):
if not data[1:].partition('.')[0].isdigit():
print('잘못된 입력입니다.')
elif data[1:].partition('.')[-1].isdigit():
isNum = True
elif data[1:].partition('.')[-1] == '' :
if '.' in data[1:].partition('.'):
print('잘못된 입력입니다.')
else:
isNum = True
else:
print('잘못된 입력입니다.')
elif data[0].isdigit():
if not data.partition('.')[0].isdigit():
print('잘못된 입력입니다.')
elif data.partition('.')[-1].isdigit():
isNum = True
elif data.partition('.')[-1] == '' :
if '.' in data.partition('.'):
print('잘못된 입력입니다.')
else:
isNum = True
else:
print('잘못된 입력입니다.')
else:
print('잘못된 입력입니다.')
if data.find('.') == -1:
data=int(data)
else:
data=float(data)
sign = np.sign(data)
if sign <= -1:
sign = '-'
elif sign >= 1:
sign = '+'
data_type = re.findall(r'\w+', str(type(data)))[1]
print('='*10, 'Homework #2', '='*10)
print(f'입력정보 : {data}\n부호 : {sign}\n수치값 타입 : {data_type}')
print('='*33)