[Python] 정수부와 소수부를 분리해 출력하는 프로그램 작성

·2023년 4월 12일
0

[ Python ]

목록 보기
7/19

num = list(input())
num_str = ''.join(num)
index_n = num_str.find('.')

r = num_str[:int(index_n)]
v = num_str.replace(num_str[:int(index_n)],'0')

print(f'{num_str}은 정수 {r}과(와) 소수점 이하 {v}로 구성')

출력 예시

🔽
입력값 >> 3.678
3.678은 정수 3과(와) 소수점 이하 0.678로 구성

🔽
입력값 >> 38.1287
38.1287은 정수 38과(와) 소수점 이하 0.1287로 구성

profile
https://dribbble.com/ohseyun

0개의 댓글