1

所以我有这样的数据输出,例如进度1:*

进度模块预告片 4:****

do_not_progress 6:******

排除2:**

但我希望它像这样显示

进步

2:

**

ETC

我将不胜感激,非常困难。

print("Progress",Progress,  ":", end= " ")
for i in range (Progress):
    print("*", end = " ")
print("\n")

print("Progress_module_trailer",Progress_module_trailer,  ":", end= " ")
for i in range (Progress_module_trailer):
    print("*", end = " ")
print("\n")

print("Do_not_progress_module_trailer",Do_not_progress_module_trailer,  ":", end= " ")
for i in range (Do_not_progress_module_trailer):
    print("*", end = " ")
print("\n")

print("Exclude",Exclude,  ":", end= " ")
for i in range (Exclude):
    print("*", end = " ")
print("\n")

print(Progress+Progress_module_trailer+Do_not_progress_module_trailer+Exclude,"Number of students in total")
4

2 回答 2

1

如果我正确地理解了\n进度之间的关系,那么数字和星星应该可以解决问题!\n 表示开始新行。例子:

    print(Hello world)

打印出来:

Hello world

    print(Hello\nworld)

打印出来:

Hello
World
于 2019-11-20T12:00:55.613 回答
1

尝试定义 print 函数的 separator 参数并使用如下f-string格式:

print("Progress", f"{Progress}:", sep='\n'))

仅供参考:默认分隔符是一个空格,可以通过每个函数调用将其更改为新行(或 2 个新行,如果您愿意)。

于 2019-11-20T11:55:51.243 回答