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

파이썬 100명의 난수로 각 계층 방문자수 및 총 수입금액 계산기

by 다니엘의 개발 이야기 2022. 5. 11.
320x100
import random

age = random.sample(range(0,100),100)

baby = []
children = []
youth = []
grownup = []
old = []

for i in age:
    if i <= 7:
        baby.append(i)
    elif i <= 13:
        children.append(i)
    elif i <= 19:
        youth.append(i)
    elif i <= 64:
        grownup.append(i)
    else:
        old.append(i)

print('-'* 40)
print('영유아\t:{}명\t: {}원'.format(len(baby),len(baby)*0))
print('어린이\t:{}명\t: {}원'.format(len(children),len(children)*200))
print('청소년\t:{}명\t: {}원'.format(len(youth),len(youth)*300))
print('성인\t:{}명\t: {}원'.format(len(grownup),len(grownup)*500))
print('어르신\t:{}명\t: {}원'.format(len(old),len(old)*0))

total = len(baby)*0 + len(children)*200 + len(youth)*300 + len(grownup)*500 +len(old)*0

print('-'* 40)
print('1일 요금 총합계: {}원'.format(format(total,',')))
print('-'* 40)
300x250