[Python] cm 을 inch 로 환산하는 코드 작성

·2023년 4월 12일
0

[ Python ]

목록 보기
1/19

✅ 1 inch == 2.54 cm 정보 활용
✅ 출력은 f-string, format, % 함수 각각 사용

📄 연습 문제

cm = int(input())
inch = cm / 2.54

print(f'{cm:.3f} / {2.54:.3f} = {cm/2.54:.3f} inch')
print('{:.3f} / {:.3f} = {:.3f} inch'.format(cm, 2.54, cm/2.54))
print('%.3f / %.3f = %.3f inch' % (cm, 2.54, cm/2.54))

📝 출력 예시

10.000 / 2.540 = 3.937 inch
10.000 / 2.540 = 3.937 inch
10.000 / 2.540 = 3.937 inch
profile
https://dribbble.com/ohseyun

0개의 댓글