Database System Concepts
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
Bartleby Related Questions Icon

Related questions

bartleby

Concept explainers

Question

This is a Python program to calculate median, average, minimum, and maximum home values from a list.

How can I format the output to look like dollar values?

Can I round the output to 2 decimal places?

Can I display commas in the output values?

#!/usr/bin/env python3
# This program uses input from the user to calculate the median, average, minimum, and maximum sale prices of a group of homes
# display welcome message
print ("Real Estate Values")
print ()
# function to sort the list
def sorting (List) :
#return the sorted list
return List.sort ()
# function to find the median cost
def medianValue (List) :
# find the length of the list
length=len (List)
# find middle item of the list
middleItem-length//2
# if length is even
if length%2==0:
# return the median cost
return (List [middleItem] +List [middleItem-l])/2
# if length is odd
anTRAURTRa
else:
#return the median cost
return List [middleItem]
#function to find the average cost
def average (List) :
#find the length of the list
length=len (List)
#calculate the total cost
totalCost=sum (List)
#return the average cost
return totalCost/length
#main function
def main () :
#create an empty list
costList=[
#prompt user to enter house cost
cost=int (input ('Enter the cost of one home or -99 to quit:') )
while (cost!=-99) :
#add element in the list
CostList.append (cost)
#prompt user to enter the house cost
COst=int
cost=int (input ('Enter the cost of one home or --99 to quit:'))
#display statement
print ("******
#display statement
print ("Prices of homes in your area:")
********")
#call the sorting function to sort the list
sorting (costList)
#display the sorted list
print (costList)
#display statement
print ("**k*******
#call and display the median cost
print ("The median value is $", medianValue (costList))
#call and display the average cost
print ("The average sale price is $", average (costList) )
******")
#display the minimum cost
print ("The minimum sale price is $", min (costList))
#display the maximum cost
print ("The maximum sale price is $", max (costList))
#calling main function
main ()
expand button
Transcribed Image Text:#!/usr/bin/env python3 # This program uses input from the user to calculate the median, average, minimum, and maximum sale prices of a group of homes # display welcome message print ("Real Estate Values") print () # function to sort the list def sorting (List) : #return the sorted list return List.sort () # function to find the median cost def medianValue (List) : # find the length of the list length=len (List) # find middle item of the list middleItem-length//2 # if length is even if length%2==0: # return the median cost return (List [middleItem] +List [middleItem-l])/2 # if length is odd anTRAURTRa else: #return the median cost return List [middleItem] #function to find the average cost def average (List) : #find the length of the list length=len (List) #calculate the total cost totalCost=sum (List) #return the average cost return totalCost/length #main function def main () : #create an empty list costList=[ #prompt user to enter house cost cost=int (input ('Enter the cost of one home or -99 to quit:') ) while (cost!=-99) : #add element in the list CostList.append (cost) #prompt user to enter the house cost COst=int cost=int (input ('Enter the cost of one home or --99 to quit:')) #display statement print ("****** #display statement print ("Prices of homes in your area:") ********") #call the sorting function to sort the list sorting (costList) #display the sorted list print (costList) #display statement print ("**k******* #call and display the median cost print ("The median value is $", medianValue (costList)) #call and display the average cost print ("The average sale price is $", average (costList) ) ******") #display the minimum cost print ("The minimum sale price is $", min (costList)) #display the maximum cost print ("The maximum sale price is $", max (costList)) #calling main function main ()
Expert Solution
Check Mark
Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education