Python Forum
why does this if-statement not work?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
why does this if-statement not work?
#1
Hello, I am the biggest noob in this forum probably, so my first question is why this simple if-statement allways
accepts the first if-statement regardless of what i put in to the 'unit' variable?

weight = float(input(f'Weight: '))
unit = input('[L]bs or [K]g: ').lower()


if unit == 'k' or 'kg':
    print(f'weight is {weight / 0.45} pounds')
elif unit == 'l' or 'lbs':
    print(f'weight is {weight * 0.45} kg')
else:
    print('Invalid unit of measurement')
thx
Reply
#2
https://python-forum.io/Thread-Multiple-...or-keyword
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#3
(Nov-15-2019, 03:07 PM)buran Wrote: https://python-forum.io/Thread-Multiple-...or-keyword
Thank you, that explained it well!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  getting an import statement to work in my program barryjo 1 1,615 Dec-06-2021, 04:28 PM
Last Post: snippsat
  Why doesn't this print statement work? stylingpat 10 5,588 Mar-23-2021, 07:54 PM
Last Post: buran
  return statement will not work TheTechRobo 2 2,587 Mar-30-2020, 06:22 PM
Last Post: TheTechRobo
  Newbie to Python Why does this if statement not work? Wrightys99 5 2,540 Mar-26-2020, 12:04 PM
Last Post: buran
  Why doesn't my loop work correctly? (problem with a break statement) steckinreinhart619 2 3,152 Jun-11-2019, 10:02 AM
Last Post: steckinreinhart619
  Python if statement docx wount work Selfiatus1 5 3,057 Jun-07-2019, 11:44 PM
Last Post: Larz60+
  Simple If Statement doesn't work Jack_Sparrow 3 3,389 May-14-2018, 09:37 AM
Last Post: ThiefOfTime

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020