当我运行此命令时,我可以输入正确的名称但是当我输入高度时,我会收到无法解决的类型错误。
floatHeight = 0
floatWeight = 0
strName = ""
strName = input("What is your name? ")
while floatHeight <= 1 or floatHeight >= 3:
floatHeight = input("What is your height in metres? ")
while floatWeight <= 10 or floatWeight >= 400:
floatWeight = input("What os your weight in kilograms? ")
print(floatWeight)
print(floatHeight)
答案 0 :(得分:1)
您需要将输入的值转换为float
:
while floatHeight <= 1 or floatHeight >= 3:
floatHeight = float(input("What is your height in metres? "))
while floatWeight <= 10 or floatWeight >= 400:
floatWeight = float(input("What os your weight in kilograms? "))
否则floatHeight
或floatWeight
将是一个字符串。幸运的是,在Python 3中,您无法比较字符串和浮点数。