
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
expand_more
expand_more
format_list_bulleted
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 ()](https://content.bartleby.com/qna-images/question/d77e1f8a-9db0-4aa0-9437-f66b9b46c9a8/217dee21-ff52-44d7-b92c-006df506a94e/edytmu.jpeg)
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

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution
Trending nowThis is a popular solution!
Step by stepSolved in 3 steps with 1 images

Knowledge Booster
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.Similar questions
- When analyzing data sets, such as data for human heights or for human weights, a common step is to adjust the data. This adjustment can be done by normalizing to values between 0 and 1, or throwing away outliers. For this program, adjust the values by dividing all values by the largest value. The input begins with an integer indicating the number of floating-point values that follow. Assume that the list will always contain positive floating-point values. Output each floating-point value with two digits after the decimal point, which can be achieved as follows:print(f'{your_value:.2f}')arrow_forwardNeed help and understanding on creating and starting the python/pycharmarrow_forwardIn python please provide the code On a piano, a key has a frequency, say f0. Each higher key (black or white) has a frequency of f0 * rn, where n is the distance (number of keys) from that key, and r is 2(1/12). Given an initial key frequency, output that frequency and the next 4 higher key frequencies. Output each floating-point value with two digits after the decimal point, which can be achieved as follows:print(f'{your_value1:.2f} {your_value2:.2f} {your_value3:.2f} {your_value4:.2f} {your_value5:.2f}') Ex: If the input is: 440 the output is: 440.00 466.16 493.88 523.25 554.37arrow_forward
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education

Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education

Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON

C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON

Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning

Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education