我可以知道这里出了什么问题吗?我试了好几次,都没能把体重降到右边


weight = input("Weight: ")
unit = input("(L)ps or (K)g: ")
if unit == "K":
V = Pounds = int(weight) * 2.20462
else :
V = Kilograms = int(weight) / 0.45

print("Your weight is " + str(V) + unit)

您应该使用float而不是int,并更改结束单位。另一方面,从磅到千克的转换有错误,需要乘以0.45或除以2.20462。

weight = input("Weight: ")
unit = input("Type L (for Lb) or K (for Kg): ")
if unit == "K":
V = float(weight) * 2.20462
new_unit = "Lb"
else :
V = float(weight) / 2.20462
#analogously: V = float(weight) * 0.4535
new_unit = "Kg"
print("Your weight is {} {}".format(V, new_unit))
weight = input("What's your current Weight: ")
unit = input("Which unit it is currently of -  (L)ps or (K)g: ")
if unit == "K":
print("Your weight in Kg is " + weight + unit)
V = int(weight) * 2.20462
print("Your weight in Pound (LBS) is " + str(V) + unit)
exit;
else:
print("Your weight in (Pound) LBS is " + weight + unit)
V = int(weight) / 2.205
print("Your weight in Kg is :" + str(V) + unit)
exit;

试试这个:

def kgConvertor(kgs):
pound = kgs * 2.2
return float(pound)
kgs = float(input("How many kgs? "))
pound = kgConvertor(kgs)
print('The amount of kgs you entered is {}. '
'This is {} in pound.'.format(kgs, pound))

最新更新