Project: Weight Converter Problem

Why does this code not work? When i type K or k it converts it to Kilograms instead of pounds

weight = input("Weight: “)
unit = input(”(L)bs or (K)g: ")

if unit == “L” or “l”:
print(f"You are {int(weight) * 0.45} Kilograms")
elif unit == “K” or “k”:
print(f"You are {int(weight) * 2.205} Pounds")

The problem is the conditionals need to have an expression on both sides of the or otherwise it is treating the literal string as a boolean (which means it gets treated as true unless it is the empty string).

So you want to use:

if unit == 'L' or unit == 'l':
  ...

Similar for the other condition. Otherwise you can convert to upper or lowercase and only do one comparison.

1 Like