我正在使用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
也许这可以做到:
number_of_policies = int(input('How many Policies will you create?: '))
policies = []
for i in range(number_of_policies):
parts = {}
parts['a'] = input('Paste in Part A of Policy: ')
parts['b'] = input('Paste in Part B of Policy: ')
parts['c'] = input('Paste in Part C of policy: ')
policies.append(parts)
for policy in policies:
print(f"n it is {policy['a']} that will be translated to {policy['b']}:{policy['c']}n")