输入字符串 str并将 str 输出到屏幕要求宽度为 20 个字符居中对齐若输入的字符串不足 20 位用填充;若输入的字符串超过 20 位则全部输出。例如输入Python时输出为Python;输入吾日三省吾身为人谋而不忠乎与朋友交而不信乎传不习乎时输出相同的字符串。
str = input() length = len(str) if length >= 20: print(str) else: left = (20 - length) // 2 right = 20 - length - left print('' * left + str + '' * right)
原文地址: https://www.cveoy.top/t/topic/N81 著作权归作者所有。请勿转载和采集!