Maximilian S.

asked • 01/22/17

basic python math problem

Peggy listed a real estate property for a commission rate of 5.0%. Peggy’s brokerage will get half of the commission and Peggy’s share will be half of that. The property sells when reduced by 20%. Write a program that prompts for the original price of the listing. Your program should output the reduced selling price and Peggy’s commission in currency format with the $ sign right up against the first digit and two decimal places. Also, display commas as appropriate for amounts over $1,000.

Im looking for the most simple way to program this in python 
 
this is what i have come up with so far 
import locale
origpr = input('what is the original price')# original full price
discopr = int(origpr * 0.80) #answer to the property sells when reduced by 20%
comish = int(discopr * 0.05)#newprice times .05
broker = int(comish *.5)#brokers half the comission
peggy = int(broker *.5) #peggys comish
print'the discounted price is $'+format(discopr,'.2f')#print the reduced
print'Peggys comission is $'+format(peggy,'.2f')#print the reduced

1 Expert Answer

By:

Doug C. answered • 01/22/17

Tutor
5.0 (1,554)

Math Tutor with Reputation to make difficult concepts understandable

Maximilian S.

Hi thanks you for your help doug C this is what i came up with

origpr = input('what is the original price')# original full price
discopr = int(origpr * 0.80) #answer to the property sells when reduced by 20%
comish = int(discopr * 0.05#newprice times .05
broker = int(broker *.5)#brokers half the comission
peggy = int(broker *.5) #peggys comissih
print 'the discounted price is $'+format(discopr,'.2f')#print the reduced
print 'peggys commission is $'+format(peggy,'.2f')#Peggy’s commission
 
im just missing how to set the commas i read about using import locale and set locale to english would present the right output but it was not the proper way to achieve the results 
Report

01/22/17

Doug C.

Hi Max,
First note that "int" is only required to convert the input string to an integer. After that you do not have to use int.
 
So, you 2nd line becomes: 
discopr = .8 * origpr
 
Here is what I came up with regarding formatting the output:
 
import locale
locale.setlocale(locale.LC_ALL,"")
'en_US.UTF-8'

currency_symbol = locale.localeconv()['currency_symbol']
 
....
 
 
print ("New Price: " + currency_symbol + locale.format("%.2f", newp, 1)) # insert commas
 
Here is some output from the program I wrote:
 
C:\Python34>python peggy.py
New Price: $25,919.90
Peggy's Commission: $324.00
 
For the above my origp was 
orig = 32399.87
 
I have not done a complete validation of the code, but this should give you the idea.
Report

01/22/17

Doug C.

Also found this, but did not try it (looks cleaner):
 
>>> import locale
>>> locale.setlocale( locale.LC_ALL, '' )
'English_United States.1252'
>>> locale.currency( 188518982.18 )
'$188518982.18'
>>> locale.currency( 188518982.18, grouping=True )
'$188,518,982.18'
Report

01/22/17

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.