# Why isnt my python code working

code:

``````weight = int(input("Weight: "))
lbs_or_kg = input("(L)bs or (K)g: ")

if lbs_or_kg.upper() == 'L':
kg = lbs_or_kg * 0.45
print(f'You are {kg} kilos.')

else:
lbs = lbs_or_kg // 0.45
print(f'You are {lbs} pounds.')
``````

idk why it isnt working

Hi @FinnifyYT, you have multiple problems with your code. I can give you hints to help, but cannot provide the full corrected code in case this is a school assignment/homework.

First of all, please use the correct type of speech marks for strings (`"string"` or `'string'`), the ones you have provided in your code gives an error.

Secondly, the indentation for the if/else statement is wrong, anything within the `if` and `else` part of the statement should be indented at least 2 lines.

Finally, you are multiplying the wrong variable by 0.45. You should be multiplying the variable `weight` instead of `lbs_or_kg`.

Hope this helps

5 Likes

Oh my thank you so much

1 Like

This wasn’t their fault actually, Discourse auto-formatting kinda did them in there.

3 Likes
``````weight = int(input("Weight: "))
lbs_or_kg = input("(L)bs or (K)g: ")

if lbs_or_kg.upper() == 'L':
kg = weight * 0.45
print(f'You are {kg} kilos.')
else:
lbs = weight // 0.45
print(f'You are {lbs} pounds.')
``````
1. In the “if” block, you are using the variable “lbs_or_kg” instead of “weight” to calculate the kilograms.
2. When converting from pounds to kilograms, you should multiply the weight by 0.45, not the string ‘lbs_or_kg’.
1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.