본문 바로가기
개발일지/Python

[복기] 천단위 포멧팅 작동안됨 (해결법 찾음)

by 개발에정착하고싶다 2022. 4. 30.
320x100
# 내가 작성했던 코드고 포멧팅으로 천단위 구분되는 것을 제외하곤 모두 정상작동한다.

type_of_gas = int(input('업종 선택(1.가정용\t2.대중탕용\t3.공업용): '))
used_gas = int(input('사용량 입력(숫자만): '))

price_used_gas = 0

if type_of_gas == 1:
    price_used_gas = 540

elif type_of_gas == 2:
    if used_gas > 300:
        price_used_gas = 2400
    elif used_gas <=300 and used_gas > 50:
        price_used_gas = 1920
    elif used_gas <= 50:
        price_used_gas = 820

elif type_of_gas == 3:
    if used_gas > 500:
        price_used_gas = 470
    elif used_gas <= 500:
        price_used_gas = 240

total_price = format(format(used_gas * price_used_gas),',')

print('='*30)
print('상수도 요금표')
print('-'*30)
print('사용량\t\t:\t요금')
print('{}   \t\t:\t{}원'.format(used_gas,total_price))

# 아니 1000단위 포멧팅이 도대체 왜 이렇게 하고 저렇게 해도 안되냐;

 

 


# 해답코드

part = int(input('업종 선택(1.가정용\t2.대중탕용\t3.공업용): '))
userWater = int(input('사용량 입력: '))
unitPrice = 0




if part == 1:
    unitPrice = 540

elif part == 2:
    if userWater <= 50:
        unitPrice = 820
    elif userWater > 50 and userWater <= 300:
        unitPrice = 1920
    elif userWater > 300:
        unitPrice = 2400

elif part == 3:
    if userWater <= 500:
        unitPrice = 240
    else:
        unitPrice = 470


print('='*30)
print('상수도 요금표')
print('-'*30)
print('사용량 : 요금')
userPrice = userWater * unitPrice
print('{} : {}원'.format(userWater, format(userPrice,',')))
########## 여기가 진짜 중요했다 나에겐
# 천의 자리가 들어가는 줄이라고 해서 전체를 포멧팅으로 묶어주는게 아니라, 천단위가 필요한 영역만
# 별도로 이중 포멧팅을 해줘서 ','처리 해준다.

print('='*30)
300x250