I've written a program that asks the user to input integers which will be placed in a list. I only want to input four integers. I'm looking for ways to make my list all zeros. Doesn't appear that this is as intuitive as arrays are in C++. Anyway this is what I got:
Isn't there an easier way to initialize all elements to zero?
numbers = [0] * 4 index = 0 while index < 4: numbers[index] = int(input("Enter a value for the list: ")) index += 1 print("\nHere is the values you entered: ", end='') for i in numbers: print(str(i) + " ", end='') print() print()According to my book the repetition operator makes multiple copies of a list and then it joins them all together. So is it doing numbers[0] + numbers[0] + numbers[0] + numbers[0] to finally get numbers[0, 0, 0, 0]?
Isn't there an easier way to initialize all elements to zero?