I don't know why this python code isn't working, please tell me why.
weight = int(input("Enter your weight:"))
Weightscale = (input("(L)bs or (K)g:"))
if Weightscale.lower == "L":
ans = (weight * 0.45)
print(f"You are {ans} Kg")
else:
ans = (weight / 0.45)
print(f"You are {ans} pound")
CodePudding user response:
You should declare weight
as a float
to have decimal values.
You must use ()
to call lower
. Then your lower
condition must compare to a lowercase letter "l"
, not "L"
:
weightscale = input("(L)bs or (K)g: ")
weight = float(input(f"Enter weight in {weightscale}: "))
# Lower needs (), then make the "L" lower too -> "l"
if weightscale.lower() == "l":
ans = (weight * 0.45)
print(f"You are {ans} Kg")
else:
ans = (weight / 0.45)
print(f"You are {ans} pound")
CodePudding user response:
I notice three mistakes in your code:
weight
is not declaredWeightscale.lower
should be a function call, i.e.Weightscale.lower()
Weightscale.lower()
will never be equal to"L"
, so yourif
block will never be treated. You should do one of the following:Weightscale.lower() == "l"
Weightscale.upper() == "L"
CodePudding user response:
Using lower and comparing "L", try:
if Weightscale.lower() == "l":