Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/314.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何在冒号后获得产品_Python_Jupyter Notebook_Jupyter_Jupyter Lab_Jupyter Irkernel - Fatal编程技术网

Python 如何在冒号后获得产品

Python 如何在冒号后获得产品,python,jupyter-notebook,jupyter,jupyter-lab,jupyter-irkernel,Python,Jupyter Notebook,Jupyter,Jupyter Lab,Jupyter Irkernel,所以我在学习这个BMI计算器程序,我希望答案写在“:”后面,而不是下面。有人能帮我吗?甚至有可能得到这样的答案吗 代码如下: name = "hello" height_m = 2 weight_kg = 110 bmi = weight_kg / (height_m ** 2) print("bmi:") print(bmi) if bmi < 25: print(name) print("is not overweig

所以我在学习这个BMI计算器程序,我希望答案写在“:”后面,而不是下面。有人能帮我吗?甚至有可能得到这样的答案吗

代码如下:

name = "hello"
height_m = 2
weight_kg = 110

bmi = weight_kg / (height_m ** 2)
print("bmi:")
print(bmi)
if bmi < 25:
    print(name)
    print("is not overweight")
else:
    print(name)
    print("is overweight")

#printed:
bmi:
27.5
hello
is overweight

#but what i want is this:
bmi: 27.5
hello is overweight
name=“你好”
高度m=2
重量_kg=110
体重指数=体重/千克/(身高**2)
打印(“bmi:)
打印(bmi)
如果体重指数<25:
印刷品(名称)
打印(“未超重”)
其他:
印刷品(名称)
打印(“超重”)
#印刷品:
体重指数:
27.5
你好
超重
#但我想要的是:
体重指数:27.5
你好,我超重了
试试这个

name = "hello"
height_m = 2
weight_kg = 110

bmi = weight_kg / (height_m ** 2)
print("bmi: {}".format(bmi)
if bmi < 25:
    print("{} is not overweight".format(name))
else:
    print("{} is overweight".format(name))

#prints:
bmi: 27.5
hello is overweight
name=“你好”
高度m=2
重量_kg=110
体重指数=体重/千克/(身高**2)
打印(“bmi:{}”。格式(bmi)
如果体重指数<25:
打印(“{}未超重”。格式(名称))
其他:
打印(“{}超重”。格式(名称))
#印刷品:
体重指数:27.5
你好,我超重了

您需要在同一个
打印
语句中放置逗号,而不是两个单独的逗号

print("bmi:",bmi)
而不是

print("bmi:")
print(bmi)
试试这个

name = "hello"
height_m = 2
weight_kg = 110

bmi = weight_kg / (height_m ** 2)
print("bmi:", end=' ')
print(bmi)
if bmi < 25:
    print(name, end=' ')
    print("is not overweight")
else:
    print(name, end=' ')
    print("is overweight")
您可以执行以下任一操作:

print("bmi:", bmi) # the simplest


这回答了你的问题吗?
print("bmi:", bmi) # the simplest
print(f"bmi: {bmi}") # f string in Python 3
print("bmi: ", end="") # Your original code, modified
print(bmi)
print("bmi: %s " % bmi) # too extreme -- don't do it for this simple case
print("bmi: {}".format(bmi)) # too extreme