我正在使用while循环来创建策略。但是,我希望政策能够 最后一次全部打印出来。目前,我只能让他们一张一张地打印。
我尝试实现一个列表,以尝试在其中存储信息以供日后调用。但是,我相信我已经超出了我目前的知识范围。我是python和一般编程的新手。我愿意接受任何建议。
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
答案 0 :(得分:1)
也许这可以做到:
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")