嘿伙计们我刚刚来到这里,我刚开始。 我试图通过简单地获取输入和进行计算来制作BMI计算器,但由于某种原因它不起作用。 这是该计划:
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'
谢谢你们!
答案 0 :(得分:0)
在你的帮助下,这是工作代码:
打印&#34;你多大了?&#34;,
age = int(raw_input())
打印&#34;你有多高?&#34;,
height = float(raw_input())
打印&#34;你的体重是多少?&#34;,
weight = float(raw_input())
print&#34;所以,你已经年复一年了,%r米高,%r公斤重。\ n
Ain太糟糕但说实话可能更好!&#34; %(
年龄,身高,体重)
重量=浮动(重量) height = float(height)
打印&#34;您的BMI是%d&#34; %(float(weight)/(float(height)* float(height)))
非常感谢你!