'second if statement will not return the correct output

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


Solution 1:[1]

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):

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 ahmed