Python Program to create an array by user input
In this program, you will learn how to create an array by user input in Python.
a = arr.array('i', [10, 20, 30, 40])
Example: How to create an array by user input in Python
import array as arr
a = arr.array('i', [])
k = int(input("Enter size of array:"))
for i in range(0, k):
num = int(input("Enter %d array element:" % (i + 1)))
a.append(num)
print("All array elements are:", end="")
for i in a:
print(i, end=" ")
Output:
Enter size of array:4
Enter 1 array element:10
Enter 2 array element:20
Enter 3 array element:30
Enter 4 array element:40
All array elements are:10 20 30 40