본문 바로가기

BOJ/Python

[BOJ/백준] 10179 - 쿠폰 (Python)

문제

문제링크

원래 가격이 주어질 때 20% 할인된 가격을 소수점 둘째자리까지 출력하라.

 

풀이

20% 할인되었다면, 원래가격의 80%로 계산하면 된다.

f-string으로 달러단위를 붙여 소수점 두번째 자리(.2f)까지만 출력한다.

 

코드

n=int(input())
for _ in range(n):
  price=float(input())
  discount_price=price*0.8
  print(f'${discount_price:.2f}')