Reputation: 1
So currently I have this code and everything runs just fine. My "min" if statement is returning all of the cars in the json file instead of the minimum if that makes sense. I have tried everything, I'm unsure if it's an indentation issue or what.
horsepower = request.args.get('horsepower')
minmax = request.args.get('minmax')
message = "<h3>HORSEPOWER "+minmax.upper()+" "+str(horsepower)+"</h3>"
path = os.getcwd() + "/cars.json"
with open(path) as f:
data = json.load(f)
for records in data:
Car = str(records["Car"])
Horse = int(records["Horsepower"])
if minmax == "max" and horsepower >= str(Horse):
message += str(Car) + " " + str(Horse) + str(max) + "<br>"
if minmax == "min" and horsepower <= str(Horse):
message += str(Car) + " " + str(Horse) + str(min) + "<br>"
return message
Upvotes: 0
Views: 25
Reputation: 5590
You have to compare numbers not string
horsepower = int(request.args.get('horsepower'))
# ...
if minmax == "max" and horsepower >= int(Horse):
# ...
if minmax == "min" and horsepower <= int(Horse):
Upvotes: 1