Python/예제
[파이썬 예제] 환전하기 - 리스트 변환
Fullyalive
2017. 8. 13. 14:36
# 원화 > 달러 > 엔화로 리스트를 변경하는 예제
def krw_to_usd(won):
return won / 1000
def usd_to_jpy(dollar):
return dollar * 125
i = 0
amounts = [1000, 2000, 3000, 5000, 8000, 13000, 21000, 34000]
print("한국 화폐: " + str(amounts))
while i < len(amounts):
amounts[i] = round(krw_to_usd(amounts[i]), 1)
i = i + 1
print("미국 화폐: " + str(amounts))
i = 0
while i < len(amounts):
amounts[i] = round(usd_to_jpy(amounts[i]), 1)
i = i + 1
print("일본 화폐: " + str(amounts))
# 결과값
한국 화폐: [1000, 2000, 3000, 5000, 8000, 13000, 21000, 34000]
미국 화폐: [1.0, 2.0, 3.0, 5.0, 8.0, 13.0, 21.0, 34.0]
일본 화폐: [125.0, 250.0, 375.0, 625.0, 1000.0, 1625.0, 2625.0, 4250.0]