ここに新しい人がいて、ちょうど始まった。 私は単純に入力を取得して計算を行うことでBMI計算機を作ろうとしましたが、何らかの理由で動作しません。 これはプログラムです:'str'型のnon-intでシーケンスを掛けよう
print "how old are you?",
age = raw_input()
print "how tall are you?",
height = raw_input()
print "how much do you weigh?",
weight = raw_input()
print "So, you're %r years old, %r meters tall and %r Kilograms heavy.\n Ain't too bad but could be better to be honest!" %(age, height, weight)
print "Your BMI is %d" % (weight (height * height))
、これが出力されます:
how old are you? 1
how tall are you? 2
how much do you weigh? 4
So, you're '1' years old, '2' meters tall and '4' Kilograms heavy.
Ain't too bad but could be better to be honest!
Traceback (most recent call last):
File "ex10.py", line 11, in <module>
print "Your BMI is %d" % (weight (height * height))
TypeError: can't multiply sequence by non-int of type 'str'
みんなありがとう!
私のコードのように行が分かれない理由はわかりません... –
[文字列をPythonで整数に変換する方法は?](http://stackoverflow.com/questions/) 642154/how-to-convert-strings-into-python) –