您好,我是 python 的初学者,我正在尝试使用用户输入制作一个列表。示例:如果用户想在列表中添加 2 样东西……比如说香蕉和苹果,他们输入 2 表示他们想要添加到列表中的东西的数量,然后输入每个水果。这应该添加两个水果,但我得到了一个错误。这是我的代码:python custom = list() addresponse = int(input('How many fruits do you want to add to your custom list. Enter Number: ')) for x in range(addresponse): customresponse = input('What is a fruit you want to add? ') custom.extend(customresponse) # Should this be custom.append? print(custom) 您必须指定什么是自定义的```pythoncustom = []addresponse = int(input(‘How many fruits do you want to add to your custom list. Enter Number: ’))
python custom = list() addresponse = int(input('How many fruits do you want to add to your custom list. Enter Number: ')) for x in range(addresponse): customresponse = input('What is a fruit you want to add? ') custom.extend(customresponse) # Should this be custom.append? print(custom)
for x in range(addresponse): customresponse = input(‘What is a fruit you want to add? ’) #use append method to add value to a list custom.append(customresponse)
print(custom)```