Hello!
So, I'm taking some classes and learning how to write sample programs in Python, and I've stalled out pretty hard on one of the sample programs. The current exercise wants me to do the following:
- Create an empty list home_prices
- While loop asks for a home price
- In the while loop, append a home price to the home_prices loop
- Print the entire home_prices list, one price per line, with a title that prints just once before the list of prices.
- Ask user for a mid-level price (not too high, not too low)
- Print a list of all home prices less than or equal to that mid-level price
- Print a list of all home prices above the mid-level price.
- Get the total of all the home prices; display that total,
- Also display the least expensive and most expensive home in the list
Steps one 1-4 are easy, and I've completed them. Steps 5-7 is where I run into a brick wall. I don't know how to split lists based on a numeric comparison to individual items within a list, since you can't compare a list and an integer directly. I was chased out of Stack Overflow for asking a stupid question, so I'm sure it's simple and I'm just blanking on something, but I could really use some help.
My stab-in-the-dark code that doesn't work is below:
import utils
home_prices = []
answer = 'yes'
while answer == 'yes':
home_prices.append(int(input("Please enter a house price between 75000 and 500000: ")))
answer = utils.yes_or_no("Do you have another house price? (Must have at least twelve for program to work accurately.)")
#end while
print('')
print('Home prices:')
n = len(home_prices)
i = 0
while i < n:
name = home_prices[i]
i = i + 1
print(name)
#end while
home1 = []
home2 = []
input = int(input("Please enter a medium priced house: "))
if home_prices => input:
home1.append(home_prices)
else:
home2.append(home_prices)
print('')
print('Affordable')
n = len(home1)
i = 0
while i < n:
name = home1[i]
i = i + 1
print(name)
print('')
print('Expensive')
n = len(home2)
i = 0
while i < n:
name = home2[i]
i = i + 1
print(name)