'<' not supported between instances of 'function' and 'float'

Viewed 684
    if bmi < 18.5:
TypeError: '<' not supported between instances of 'function' and 'float'

I don't really understand what I'm doing wrong. For me it seems everything to be fine but when I run it it gives me that error that I previously wrote. Any help is highly appreciated. Here's my code:

#pengguna masukkan nama berat tinggire
nama=str(input("Masukkan nama anda:"))
berat=int(input("Masukkan berat anda:"))
tinggi=float(input("Masukkan tinggi anda dalam meter:"))

#formula bmi
bmi=berat/(tinggi*tinggi)

#kategori-kategori berat
kategori_1 =str("underweight")
kategori_2 =str("normal")
kategori_3 =str("overweight")
kategori_4 =str("obese")

#mengkategorikan berdasarkan bmi
def bmi_kategori(bmi):
    return bmi
if bmi < 18.5:
   kategori =kategori_1
elif bmi < 24.9:
    kategori =kategori_2
elif bmi < 29.9:
    kategori =kategori_3
else:
    kategori = kategori_4

print("nama anda ialah:", nama)
print("kategori anda ialah:",kategori)
print("bmi anda ialah:", bmi)

Sorry if my grammar is bad. English is not my first language, also I'm new to python.

2 Answers

bmi here is used for a function name, for a parameter name, for a variable name in the scope of the whole file.

There are rules that can sort out which of these has precedence in various contexts, but it will be much simpler and cleaner to rename these. Eliminate the function (that does nothing) or rename the function and parameter: def get_bmi(b): return b

You have 2 things called bmi : a float and a function. By the way the function defined by def bmi(bmi): return bmi is actually useless, it is just a function that returns the argument you give.

So you can just remove this :

def bmi(bmi):
    return bmi
Related