# py 3.7

import locale

source = '''

# calculates price of houses

house num 100

house price 250,000

calculate price

'''

def calculate(houses, unit_price):

calc_price = houses * unit_price

return calc_price

def output(price):

# $ 250 000

locale.setlocale(locale.LC_ALL, '')

return f'{locale.currency(price, grouping=True)}'

def sanitise_price(price):

# 250,000 -> 250 000

return int(price.replace(',', ''))

def parse(source):

houses = 0

unit_price = 0

calc_price = 0

lines = [i for i in source.split('\n') if i]

for line in lines:

# simplification

tokens = line.split()

# comment

if tokens[0] == '#':

continue

# commands

elif tokens[0] == 'house':

if tokens[1] == 'num':

houses = sanitise_price(tokens[2])

elif tokens[1] == 'price':

unit_price = sanitise_price(tokens[2])

elif tokens[0] == 'calculate' and tokens[1] == 'price':

calc_price = calculate(houses, unit_price)

print(output(calc_price))

parse(source)