When you write:
if unit == 'L' or 'l':
it's getting parsed as:
if (unit == 'L') or ('l'):
which is equivalent to:
if (unit == 'L') or (bool('l') is True):
bool('l') is always true, which is why none of the elif/else blocks get executed.
This is what you intended:
if unit == 'L' or unit == 'l':
If you prefer to avoid the re-use of unit == , you can re-write it as:
if unit.upper() == 'L':
or even:
if unit in ('L', 'l'):
I hope this helps.
Addition: (2023-12-13)
An even better way of checking case-insensitive equivalence is to use the str.casefold method on both strings:
if unit.casefold() == 'L'.casefold():
The str.casefold method returns a version of its string suitable for caseless comparisons. It might seem a little overkill in the example I just gave, but consider a comparison against "Washington". You could write this:
if name.lower() == "washington":
or you could check against a tuple of possibilities, like this:
if name in ('WASHINGTON', 'Washington', 'washington'):
(Note that this last example is not a true case-less comparison, as it won't match "WashingTon".)
By using str.casefold you can simply write:
if name.casefold() == "Washington".casefold():
So how is this better than simply writing the slightly shorter:
if name.lower() == "washington":
Well, if you use str.lower, you'd have to hard-code the string in lower-case, which may not be the canonical form of the string. Which means that if you change the string, you'd have to be careful of keeping it lower-case; if you accidentally use one or more capital letters in your hard-coded string, your comparison will always fail.
If you want to do a case-less comparison against several hard-coded strings, you can map the possibilities with map(str.casefold, (...)) and use in to check for the choice among the possibilities:
if choice.casefold() in map(str.casefold, ('Y', 'yes', 'Affirmative')):
This check will evaluate to True if the choice is yes, Yes, YES, Y, y, YeS, yES, Affirmative, affirmative, AFFIRMative, etc. (It's nice that you do not have to worry about how you capitalize the possibilities, so you can focus on writing them out using the capitalizations that make the most sense to the program you're writing.)