首先,我是一般编程的新手,所以这意味着我也是 python 的新手,所以输入缓慢以便我跟上。 我试图将包含用户输入的变量的文本行居中。像这样:
age = input ("How old are you? ")
print ("{: ^80}".format("You are", (age), "years old."))
我已经尝试了很多我能想到的方法来使它在整行阅读中居中。 . . 你40岁了。 (当然,假设用户输入 = 40) 没有运气。我做错了什么?
谢谢, 罗伯特
最佳答案
在字符串上使用 .center() 会在它们的两边填充空格。
print('You are {} years old'.format(age).center(80))
关于python - 带有变量python3.6的中心文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50438450/