-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrealestateanalyzer.py
More file actions
61 lines (54 loc) · 2.01 KB
/
realestateanalyzer.py
File metadata and controls
61 lines (54 loc) · 2.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#Name: Mark Dymek
#Purpose: Create a program for real estate sales
#Date: 5/1/2025
NUMBER_FORMAT = ",.2f"
def getFloatInput(prompt):#handle getting input and make sure its correct
while True:
try:
fValue = float(input("Please enter a positive amount: "))
if fValue > 0:
return fValue
else:
print("Please enter a positive non-zero number")
except ValueError:
print("Invalid input. Please enter a numeric value.")
def getMedian(salesList): #get the average
iNumber = len(salesList)
sortedList = sorted(salesList)
if iNumber % 2 == 1:
return sortedList[iNumber // 2]
else:
iMid = iNumber // 2
return (sortedList[iMid - 1] + sortedList[iMid]) / 2
def main():#our main code block. calls our functions.
salesList = []
while True:
choice = input("Do you want to enter a value yes or no?").strip().upper()
if choice == "N":
break
elif choice == "Y":
amount = getFloatInput("Enter the property value: ")
salesList.append(amount)
else:
print("Invalid input. Please enter Y or N.")
# If no sales were entered, exit cleanly
if not salesList:
print("No sales data entered. Exiting the program.")
return
# Print each property’s sale
for i, sale in enumerate(sorted(salesList), start=1):
print(f"Property {i}: ${sale:{NUMBER_FORMAT}}")
# Summary of sales
print(f"{'Lowest sale:':<20}${min(salesList):>15,.2f}")
print(f"{'Highest sale:':<20}${max(salesList):>15,.2f}")
fTotal = sum(salesList)
print(f"{'Total sales:':<20}${fTotal:>15,.2f}")
iItems = len(salesList)
fAverage = fTotal / iItems
print(f"{'Average sale:':<20}${fAverage:>15,.2f}")
fMedian = getMedian(salesList)
print(f"{'Median sale:':<20}${fMedian:>15,.2f}")
fCommission = 0.03 * fTotal
print(f"{'Commission:':<20}${fCommission:>15,.2f}")
if __name__ == "__main__":
main()