count = input("Please enter number of products: ")
fruit = []
for i in range(4):
name = input(f"Name of product {i+1}: ")
weight = input(f"Weight of product {i+1}: ")
fruit.append( (name, weight) )
print(fruit)
运行结果:
>>> count = input("Please enter number of products: ")
Please enter number of products: 4
>>> fruit = []
>>> for i in range(4):
... name = input(f"Name of product {i+1}: ")
... weight = input(f"Weight of product {i+1}: ")
... fruit.append( (name, weight) )
...
Name of product 1: Apple
Weight of product 1: 2
Name of product 2: Banana
Weight of product 2: 3
Name of product 3: Pear
Weight of product 3: 1
Name of product 4: Pineapple
Weight of product 4: 3
>>> print(fruit)
[('Apple', '2'), ('Banana', '3'), ('Pear', '1'), ('Pineapple', '3')]
>>>
如果你满意我的回答,请点采纳,我很感谢你的认可。