-1

I am new to the python language and I can not find how to write these functions in my books. They mostly write in pseudocode and expect you just to know how to exactly code it. I wanted to ask for help before I spend a couple of hours searching with no results.

This program is supposed to take the user's house prices and find the median, average, maximum, and minimum.

#This program asks for prices of houses from the user, then it takes the input
#and calculates the AVG, MAX, MIN, and MED.
print("  Real Estate Program ")
print()
print("**********************************************************************")

#Will get the user's input about the price houses in their area
prices = []
cost = 0
while cost != -99:
    cost = input("Enter cost of one home or -99 to quit: ")
    prices.append(cost)
    if cost == "-99":
        break
    else:
        continue


print("*********************************************************************")

#removes -99 from list
prices.pop(-1)
print("Prices of homes in your area:")
print(prices)
print()

#this find the maximum value of the houses
print ("The maximum sale price is:", max(prices))

#this find the minimum value of the houses
print ("The minimum sale price is:", min(prices))
MistB
  • 1
  • 1
  • 3
    Does this answer your question? [Finding the average of a list](https://stackoverflow.com/questions/9039961/finding-the-average-of-a-list) [Finding median of list in python](https://stackoverflow.com/questions/24101524/finding-median-of-list-in-python). Definitely took less than a minute of searching to get those results FYI – not_speshal Nov 05 '21 at 22:07
  • https://docs.python.org/3/library/statistics.html – PM 77-1 Nov 05 '21 at 22:08

1 Answers1

0

For both of these you can use the statistics module. You can call the mean and median function from the statistics with a list of items. So you can add

from statistics import mean, median

print("The average sale price is:", mean(prices))
print("The median sale price is:", median(prices))
HostedPosted
  • 88
  • 1
  • 4