samedi 13 juin 2020

Why do i get different results when i use lower() and when i not use lower()? [duplicate]

when i not use .lower(): I don't get the desired result

name=input("Insert your name here: \n")
weight=float(input("Enter your weight here: \n"))
unit=input("What unit do you want to use? \n")

if unit == "kgs" or "KGS":
    print(f"{name} is {weight} kgs.")
elif unit == "LBS" or "lbs":
    convert=weight/2.2
    print(f"{name} is {convert} lbs.")
else:
    print("Please re-enter.")

when I use .lower(): I got the desired result

name=input("Insert your name here: \n")
weight=float(input("Enter your weight here: \n"))
unit=input("What unit do you want to use? \n")

if unit.lower() == "kgs":
    print(f"{name} is {weight} kgs.")
elif unit.lower()== "lbs":
    convert=weight/2.2
    print(f"{name} is {convert} lbs.")
else:
    print("Please re-enter.")

Thanks for the help.

Aucun commentaire:

Enregistrer un commentaire