打印时的额外空格 [英] Extra spaces when printing

查看:40
本文介绍了打印时的额外空格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经阅读了许多 Python 空白删除问题和答案,但一直找不到我要找的内容.这是一个显示问题的具体示例的小程序.我非常感谢你的帮助.

I've read through a number of the python whitespace removal questions and answers but haven't been able to find what I'm looking for. Here is a small program that shows a specific example of the issue. I greatly appreciate your help.

import random

math_score = random.randint(200,800)
math_guess = int(input("\n\nWhat score do you think you earned on the math section (200 to 800)?\t"))
print ("\n\n\nOn the math section, you guessed",math_guess,", and your actual score was",math_score,"!")

所以这是我的问题:

当我执行程序时,我得到以下结果:

When I execute the program, I get the following results:

在数学部分,你猜了 600 ,你的实际分数是 717 !

我想删除句子中每个变量后面的空格.在这种情况下,600 和,"之间的空格以及 717 和!"之间的空格.

I would like to remove the space that follows each variable in the sentence. In this case the space between 600 and the "," and the space between 717 and the "!".

是否有解决此问题的标准方法?

Is there a standard way to approach this issue?

推荐答案

是的,format 你的字符串:

print("... you guessed {}, and ... was {}!".format(math_guess, math_score))

这篇关于打印时的额外空格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆