Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/18.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 3.x 如何在Python3.x中打印用户输入_Python 3.x_Python 2.7 - Fatal编程技术网

Python 3.x 如何在Python3.x中打印用户输入

Python 3.x 如何在Python3.x中打印用户输入,python-3.x,python-2.7,Python 3.x,Python 2.7,如何在Python3.x中以下面的格式打印下面的行 print ("How old are you?"), age = input () print ("How tall are you ?"), height = input () print ("How much do you weigh?"), weight = input() print("so , you're % year old, % ft tall and % kg heavy.")% (age,height,weight)

如何在Python3.x中以下面的格式打印下面的行

print ("How old are you?"),
age = input ()
print ("How tall are you ?"),
height = input ()
print ("How much do you weigh?"),
weight = input()

print("so , you're % year old, % ft tall and % kg heavy.")% (age,height,weight)
错误:- 那么,你是%x岁、%x英尺高、%x千克重

回溯(最近一次调用):文件“C:/Narendra/Ethans 7月8日 Python批处理/Exercises/Python3/ex11.py”,第8行,在 打印(“因此,您是%x岁、%x英尺高、%x千克重。”)%(年龄、身高、体重)类型错误:不支持%的操作数类型: “非类型”和“元组”


格式运算符
%
处理字符串,而不是整个
print
函数,该函数始终返回
None
。此外,还需要使用规范(如
%s
)指定占位符的格式

print("so , you're %s year old, %s ft tall and %s kg heavy." % (age,height,weight))

如果您使用的是Python>=3.6:请使用
f-string

Ex:

age = input ("How old are you?\n");

height = input ("How tall are you ?\n");

weight = input("How much do you weigh?\n");

print(f"so , you're {age} year old, {height} ft tall and {weight} kg heavy.")
print("so , you're {0} year old, {1} ft tall and {2} kg heavy.".format(age, height, weight))
str.format

Ex:

age = input ("How old are you?\n");

height = input ("How tall are you ?\n");

weight = input("How much do you weigh?\n");

print(f"so , you're {age} year old, {height} ft tall and {weight} kg heavy.")
print("so , you're {0} year old, {1} ft tall and {2} kg heavy.".format(age, height, weight))
我会像这样使用.format()函数

age = input('How old are you? ')
height = input('How tall are you? ' )
weight = input('How much do you weigh? ')

print(("so, you're {} year old, {} ft tall and {} kg heavy").format(age,height,weight))

完美工作:你多大了?你有多高?你体重多少?45岁,你23岁,3英尺高,45公斤重