打印时,我必须将几个变量显示为磅和英寸。
while True:
name = input("\nEnter players name or, 0 to quit: ")
if name == "0":
break
height = float(input("Enter players height in inches: "))
weight = float(input("Enter players weight in pounds: "))
bmi = weight * 703 / height * height
print("\nBMI Profile Of %s" % name,"Height: ",height,"Weight: ",weight,"BMI Index: ",bmi,sep = "\n")
所以我的问题是如何让变量高度显示为英寸或"和重量为磅。
答案 0 :(得分:0)
使用str
将这些整数转换为使用+:
print("\nBMI Profile Of %s" % name,"Height: ",str(height)+" inches","Weight: ",str(weight) + " lbs","BMI Index: ",bmi,sep = "\n")
输出:
BMI Profile Of Scott
Height:
60 inches
Weight:
200 lbs
BMI Index:
140600.0
答案 1 :(得分:0)
您可以按照以下方式使用。并使用str
进行汇总。高度为"
,重量为lbs
。
while True:
name = input("\nEnter players name or, 0 to quit: ")
if name == "0":
break
height = float(input("Enter players height in inches: "))
weight = float(input("Enter players weight in pounds: "))
bmi = weight * 703 / height * height
print("\nBMI Profile Of %s" % name,"Height: ",str(height) + '″', "Weight: ",str(weight) + " lbs","BMI Index: ",bmi,sep = "\n")
<强>输出强>
BMI Profile Of Test
Height:
186.0″
Weight:
75.0 lbs
BMI Index:
52724.99