Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Python Code: Need help with def main (): section. Output should look like this: Enter home price # 1 : $ Enter home owner #

Python Code: Need help with "def main ():" section.

Output should look like this:

Enter home price # 1 : $

Enter home owner # 1 :

Enter home price # 2 : $

Enter home owner # 2 :

Enter home price # 3 : $

Enter home owner # 3 :

Enter home price # 4 : $

Enter home owner # 4 :

Enter home price # 5 : $

Enter home owner # 5 :

Enter home price # 6 : $

Enter home owner # 6 :

Enter home price # 7 : $

Enter home owner # 7 :

Enter home price # 8 : $

Enter home owner # 8 :

Enter home price # 9 : $

Enter home owner # 9 :

Welcome to the Botany Bay home sales calculator This program will calculate the average selling price of the homes sold this past year. It will then determine how many homes sold above the average, how many homes sold below the average, the highest priced home and the lowest priced home. =======================================================================

Menu Choices:

P = Print Prices & Home Owners

A = Print Average Home Price

AB = Print Homes Sold Above & Below Average

H = Print Highest Home Price & Owner

L = Print Lowest Home Price & Owner

Q = Quit Program

Enter your choice:

Botany Bay Home Sales *********************************

1 : Conway $ 101,600.00

2 : Hampton $ 165,850.00

3 : Kennedy $ 190,400.00

4 : Sawyer $ 260,600.00

5 : Anderson $ 304,700.00

6 : Davey $ 224,975.00

7 : Blake $ 201,200.00

8 : Georges $ 175,800.00

9 : Parker $ 189,600.00

Menu Choices:

P = Print Prices & Home Owners

A = Print Average Home Price

AB = Print Homes Sold Above & Below Average

H = Print Highest Home Price & Owner

L = Print Lowest Home Price & Owner

Q = Quit Program

Enter your choice:

#The program will allow the user to enter in the selling prices of homes sold #in a subdivision. It will calculate the average selling price and then #determine how many homes were sold above the average and how many homes were #sold below the average. def PrintMessage(): #Welcome Message print("Welcome to the Botany Bay home sales calculator") print("This program will calculate the average selling price of the homes") print("sold this past year. It will then determine how many homes sold above") print("the average, how many homes sold below the average, the highest priced") print("home and the lowest priced home.") print("=======================================================================") print() def PrintLists (Prices, HomeOwners): Prices = ['125900', '115000', '105900', '85000', '150000', '155249', '97500'] HomeOwners = ['Carson','Smith','Jackson','Swanson','Perry','Beufort', 'Anderson'] print("Botany Bay Home Sales") print("*********************************") #Print the Prices array for i in range(len(Prices)): #To get your output to match use the tab character (\t) and the format function #with a ,.2f mask print('{:d}'.format(i + 1), ': ${:,.2f}'.format(int(Prices[i])))

print()

def DetermineAverage(Prices): average = 0.0 sum1 = 0.0 for i in range(len(Prices)): sum1 += float(Prices[i]) average = sum1/len(Prices) #Print average print("The average selling price is: $", format(average, ',.2f')) print() return average def AboveBelowAvg(Prices, average): numabove = 0 numbelow = 0 for i in range(len(Prices)): if float(Prices[i]) > average: numabove += 1 if float(Prices[i]) < average: numbelow += 1 #print the number of homes sold above and below the average print("The number of homes selling above average are: ", numabove) print("The number of homes selling below average are: ", numbelow) print()

def DetermineHighest(Prices, HomeOwners): highvalue = Prices[0] highowner = HomeOwners[0]

#Determine Highest priced home and home owner for i in range(len(Prices)): if (int(Prices[i]) > highvalue): highvalue = int(Prices[i]) highowner = str(HomeOwners[i]) #print out highest value and the owner of that house print("The highest selling house was: $", format(highvalue, ',.2f'), "\tOwned by: ", highowner) print()

return highvalue, highowner

def DetermineLowest(Prices, HomeOwners): lowvalue = Prices[0] lowowner = HomeOwners[0] for i in range(len(Prices)): if (int(Prices[i]) < lowvalue): lowvalue = int(Prices[i]) lowowner = str(HomeOwners[i])

#print out lowest value and the owner of that house print("The lowest selling house was: $", format(lowvalue, ',.2f'), "\tOwned by: ", lowowner) print() return lowvalue, lowowner

def GetChoice(): #local variables userchoice = str() #display menu print() print("Menu Choices:") print("\tP\t=\tPrint Prices & Home Owners") print("\tA\t=\tPrint Average Home Price") print("\tAB\t=\tPrint Homes Sold Above & Below Average") print("\tH\t=\tPrint Highest Home Price & Owner") print("\tL\t=\tPrint Lowest Home Price & Owner") print("\tQ\t=\tQuit Program") print() userchoice = input("Enter your choice: ") userchoice = userchoice.upper() print()

return userchoice

def FillArrays(): #local variables index = int() prices = list() owners = list() oneprice = float() oneowner = str() for index in range(0, 9): print("Enter home price #", index + 1,": $") oneprice = float(input()) prices.append(oneprice) print("Enter home owner #", index + 1,": ") oneowner = input() owners.append(oneowner) #end loop return prices, owners

def main(): #declare the prices and home owners arrays Prices=list() HomeOwners = list() average = float() highprice = float() highname = str() lowprice = float() lowname = str() choice = str()

#Fill the array with 9 elements Prices, HomeOwners = FillArrays() #Loop that allows the user to choose which function to run PrintMessage() #Get the user's choice choice = GetChoice() #Finish loop main()

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Spatial Databases A Tour

Authors: Shashi Shekhar, Sanjay Chawla

1st Edition

0130174807, 978-0130174802

More Books

Students also viewed these Databases questions