0

How can I fix this?

list1 = [1, 2, 3] again = 'y' while again == 'y': number = input("Enter a number: ") print("Is there another?") again = input("Enter y for yes or n for no: ") #Add input values onto the list list1.append([number] * 2) I want: list1 = [1, 2, 3, 4, 4, 5, 5, 6, 6] What I'm getting is: list1 = [1, 2, 3, [4, 4], [5, 5], [6, 6]]

25th Nov 2019, 2:53 AM
Steven Iannucci
Steven Iannucci - avatar
2 Answers
0
list1.append(number) ?
25th Nov 2019, 2:59 AM
Taste
Taste - avatar
0
Use extend() instead of append(). lst = [1, 2, 3] lst.extend([4]*2) print(lst) # [1, 2, 3, 4]
25th Nov 2019, 3:44 AM
Diego
Diego - avatar