我被要求完成的代码的目的是接收所给库存的输入,并将它们作为一个列表在一行中返回。然后在第二行,复制该列表,但这次将数字加倍。
所给的输入为:
Choc 5; Vani 10; Stra 7; Choc 3; Stra 4
期望的输出是:
[['Choc', 5], ['Vani', 10], ['Stra', 7], ['Choc', 3], ['Stra', 4]]
[['Choc', 10], ['Vani', 20], ['Stra', 14], ['Choc', 6], ['Stra, 8]]
我已经成功地得到了第一行所需的输出,但是我不知道如何成功完成第二行。
这是代码:
def process_input(lst):
result = []
for string in lines:
res = string.split()
result.append([res[0], int(res[1])])
return result
def duplicate_inventory(invent):
# your code here
return = []
return result
# DON’T modify the code below
string = input()
lines = []
while string != "END":
lines.append(string)
string = input()
inventory1 = process_input(lines)
inventory2 = duplicate_inventory(inventory1)
print(inventory1)
print(inventory2)