【发布时间】:2019-12-23 20:12:44
【问题描述】:
我正在使用 while 循环来创建策略。但是,我希望政策是 最后一次性打印出来。目前,我只能让它们一张一张打印出来。
我尝试实现一个列表来尝试在其中存储信息以便稍后调用它。但是,我相信我正在超越我目前的知识。我是 python 和一般编程的新手。我愿意接受任何建议或意见。
这是针对 Python3 的。
我目前拥有的是以下
NumberOfPolicies = int(input ('How many Policies will you create?: '))
counter = 0
while counter < NumberOfPolicies:
PartA = input('Paste in Part A of Policy: ')
PartB = input ("Paste in Part B of Policy: ")
PartC = input("Paste in Part C of policy: ")
NumberOfPolicies -= 1
print ('\n it is ' + PartA + ' that will be translated to '+
PartB+':'+PartC+'\n')
输出如下。我希望首先提出所有问题,并在最后一次将输出全部吐出。
How many Policies will you create?: 2
Paste in Part A of Policy: 20
Paste in Part B of Policy: 20
Paste in Part C of policy: 20
it is 20 that will be translated to 20:20
Paste in Part A of Policy: 30
Paste in Part B of Policy: 30
Paste in Part C of policy: 30
it is 30 that will be translated to 30:30
【问题讨论】:
-
将输入存储在一个列表中,然后对其进行迭代
-
这是一个完美的解决方案。非常感谢。
-
如果您喜欢这个解决方案,请点击解决方案左侧的“v”,这样我的努力就会得到回报;-)
-
完成!再次感谢!
标签: python-3.x while-loop user-input