2016-04-04 18 views
1

これを実行すると、名前を入力することはできますが、高さを入力すると、並べ替えできない型エラーが発生します。並べ替え不可能な型intと文字列

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) 

答えて

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では文字列と浮動小数点数を比較することはできません。

+0

あなたのために機能しますか? –

関連する問題