Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.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_String_Formatting - Fatal编程技术网

python中运算符的字符串格式错误

python中运算符的字符串格式错误,python,string,formatting,Python,String,Formatting,使用Python字符串格式,我的预期输出是: If you took 19 and 13 and added them, you would get 22 但是我不太确定我是否做得很好。我不断地发现这个错误: Not all arguments converted during string formatting 你能帮忙吗 代码: 您只是缺少字符串中最后%后面的最后一个's' print "If you took %s and %s and added them, then you wi

使用Python字符串格式,我的预期输出是:

If you took 19 and 13 and added them, you would get 22
但是我不太确定我是否做得很好。我不断地发现这个错误:

 Not all arguments converted during string formatting
你能帮忙吗

代码:


您只是缺少字符串中最后%后面的最后一个's'

print "If you took %s and %s and added them, then you will get %s" %(my_age,teenager,my_age + teenager)

在上次
%%
之后缺少说明符。您需要:
“获取%d”
@TKA如果您得到想要的答案,请不要忘记单击复选标记。如果答案是有帮助的,但不完全正确,礼貌的做法是竖起大拇指表示感谢。
print "If you took %s and %s and added them, then you will get %s" %(my_age,teenager,my_age + teenager)