Reputation: 11
now I just can get the ". " in after the number, I've tried many different ways it just keep showing errors or to much spaces.
current_price = int(input())
last_months_price = int(input())
price_change = current_price - last_months_price
monthly_mortagae = (current_price*0.045)/12
print('This house is','${0}'.format(current_price),'The change is','${0}'.format(price_change),'since last month.')
print('The estimated monthly mortgage is','${}'.format('%0.2f' %monthly_mortagae))
Input
200000
210000
Your output
This house is $200000 The change is $-10000 since last month.
The estimated monthly mortgage is $750.00
Expected output
This house is $200000. The change is $-10000 since last month.
The estimated monthly mortgage is $750.00.
Upvotes: 1
Views: 1291
Reputation: 62403
f-strings
:%s
)current_price = 200000
last_months_price = 210000
price_change = current_price - last_months_price
monthly_mortagae = (current_price*0.045)/12
print(f'This house is ${current_price}. The change is ${price_change} since last month.'.replace('$-','-$'))
print(f'The estimated monthly mortgage is ${monthly_mortagae:0.02f}.'.replace('$-','-$'))
print(f"""This house is ${current_price}. The change is ${price_change} since last month.
The estimated monthly mortgage is ${monthly_mortagae:0.02f}.""".replace('$-','-$'))
"""some text"""
allows for a standard carriage return instead of \n
print("""this
is
a
sentence""")
this
is
a
sentence
This house is $200000. The change is -$10000 since last month.
The estimated monthly mortgage is $750.00.
.replace('$-','-$')
gets the negative sign to the left of $.Upvotes: 0
Reputation: 22776
Why not just insert it in the string, and use only one format:
print('This house is ${0}. The change is ${1} since last month.'.format(current_price, price_change))
print('The estimated monthly mortgage is ${:0.2f}.'.format(monthly_mortagae))
With just one print statement:
print('This house is ${0}. The change is ${1} since last month.\nThe estimated monthly mortgage is ${2:0.2f}.'.format(current_price, price_change, monthly_mortagae))
Upvotes: 2