Jun-29-2022, 02:11 PM
Ok so I'm brand new to coding and following a YouTube video for learning python, one of the exercises is to make a simple weight conversion program. I thought I understood it but I'm at a complete loss. The user enters their weight, then it asks if that was in kgs. or lbs. if the user enters a k (higher or lower case) then it will convert to lbs and vice versa. Now the problem I'm having is that the script runs but only outputs the first if statement. I have no idea why. This is my code
weight = float(input("Enter your weight ")) unit = input(" Is that (K)Kgs or (L)lbs ") conversion = 0.45 if unit == "K" or "k": convertlbs = (float)(weight * conversion) print (convertlbs) elif unit == "L" or "l": convertkgs = (float)(weight / conversion) print (convertkgs) else: print ("wrong input")Could someone please explain why this is not working? From what I understand the first if statement is checking to see if the user input for unit is equal to K or k, if it is then it should times their weight by 0.45, if its not true then it should move onto the next if statement to see if its an L or l, then dividing my 0.45. If neither of these inputs are true then it should print wrong input