ARRAY Example 1
(Mind the proper indentation, please arrange each line of code.)
import array
NumberofItems=int(10)
k=0
ProductPrice=array.array('i', range(NumberofItems))
while (k<10):
ProductPrice[k]=int(input("Enter the product price: " ))
k=k+1
k=0
print(""The product prices are: ")
while (k<10):
print(ProductPrice[k])
k=k+1
2-DIMENSIONAL ARRAY Example 2
(Mind the proper indentation, please arrange each line of code.)
import array
Array_2d = [[10, 2, 15, 12], [3, 12 ,8], [10, 8, 12, 5], [12,15,8,6]]
for row in Array_2d:
for element in row:
print(element, end = " ")
print()
XXX
2-DIMENSIONAL ARRAY Example 3
(Mind the proper indentation, please arrange each line of code.)
Example on having 10 inputted numbers and segregating them of either the number is ODD or EVEN
#declaring an array
import array
a=array.array('i',range(10))
#entering data into array
i=0
while(i<10):
a[i]=int(input("Enter element:"))
i=i+1
even=array.array('i',range(10))
odd=array.array('i',range(10))
j=0
k=0
l=0
#separating even and odd numbers into separate list
while (j<10):
if(a[j]%2==0):
even[k]=a[j]
k=k+1
else:
odd[l]=a[j]
l=l+1
j=j+1
#printing both the lists
print("The even list")
x=0
while (x<k):
print(even[x],end=" ")
x=x+1
print("\nThe odd list")
y=0
while (y<l):
print(odd[y],end=" ")
y=y+1