0

I'm a beginner in Python and was using Mosh's "Python for Beginners- Learn Python in 1" Hour course to learn it. The third exercise(36:16 - 41:15) requires us to create a simple Pounds to Kilograms or Kilograms to Pounds calculator.

For whatever reason, my code keeps using the calculations for Pounds to Kilograms, regardless of my input.

Here is my current code:

L = "Pounds"
K= " Kilo"
l = L
k = K

Weight = float(input("Provide Weight: "))
K_L = input("What metric did you use? ")

if K_L == l or L:
    print("Weight in KG is: " + (str(Weight*0.454)))
else:
    print("Weight in Lbs: " + (str(Weight*2.205)))
print("Done")

Test 1:

Provide Weight: 1
What metric did you use? l
Weight in KG is: 0.454
Done

Test 2:

Provide Weight: 1
What metric did you use? k
Weight in KG is: 0.454
Done

I've tried to fix it by separating them into two different if functions or using elif, but they resulted in the same issue for me. I was hoping to figure out why this code is wrong and why it keeps using the Pounds to Kilograms calculations, regardless of the input for metric usage.

mkrieger1
  • 19,194
  • 5
  • 54
  • 65

0 Answers0