dimanche 27 octobre 2019

Two different ways of writing the If Statement. Why the second is not working?

I'm currently learning about "if statements" and I did a weight converter as an exercise.

This is the correct way and it's fine, I understand it:

weight=int(input("your weight: "))
choice=input("lbs[L] or kilos[K] ? ")

if choice.upper() == "L":
    print(f"your weight is {weight * 0.45} kilograms")
elif choice.upper() == "K":
    print(f"your weight is {weight / 0.45} pounds ")
else:
    print("choose lbs or kilograms")

But I did this in my way and it is not working, but why?:

weight=int(input("your weight: "))
choice=input("lbs[L] or kilos[K] ? ")

if choice == "L" or "l":
    print(f"your weight is {weight * 0.45} kilograms")
elif choice == "K" or "k":
    print(f"your weight is {weight / 0.45} pounds ")
else:
    print("choose lbs or kilograms")

Please if someone could tell me why is the second code not working ? I will be glad.

Aucun commentaire:

Enregistrer un commentaire