codescracker


python

Python One Dimensional Array Program



« Previous Program Next Program »


One Dimensional Array Program in Python

To perform one dimensional array in python, follow the program given below. This program illustrates how to use one dimensional array in python.

Python Programming Code to One Dimensional Array

Following python program ask from user to enter the total number of elements, he/she wants to store in the array. And then store all the elements in the array. The value of the element starts from 1 to the number of term he/she entered:

# Python Program - One Dimensional Array
		
while True:
	print("Enter 'x' for exit.")
	nval = input("How many element you want to store in the array ? ")
	if nval == 'x':
		break
	else:
		n = int(nval)
		arr = []
		for i in range(1, n+1):
			arr.append(i)
		print("\nElements in Array are:")
		for i in range(0, n):
			print(arr[i], end=" ")
		print("\n")

Here is the sample run of the above python program to illustrate one dimensional array:

python one dimensional array

Same Program in Other Languages

You may also like to learn or practice the same program in other popular programming languages:


« Previous Program Next Program »




Tools
Calculator

Quick Links
Signup - Login - Give Online Test