因此,我尝试使用Python 2.7进行简单的计算,代码如下:
print 'In SchmooLand everyone is 9.33356564 times heavier than on earth.\n'
weight = float(raw_input('How much do you weigh on Earth in pounds?\n'))
print 'In SchmooLand you would weigh'
print weight * 9.3356564
print 'in pounds'
输出看起来像这样
How much do you weigh on Earth in pounds?
235423423
In SchmooLand you would weigh
2197832185.64
in pounds
我如何在字符串的同一行上打印权重计算的结果,以便它们都可以像这样一起打印
In SchmooLand you would weigh 2197832185.64 in pounds
我总计n00b-感谢您的帮助!
最佳答案
在每个打印行的末尾添加一个逗号,以避免隐式换行符:
print 'In SchmooLand you would weigh',
print weight * 9.3356564,
print 'in pounds',
从
print
documentation:除非打印语句以逗号结尾,否则将在末尾写入“ \ n”字符。