+ 1
Python array
I need to use a a array with input, x=input() print(arr[x])
2 Answers
+ 2
Thanks
+ 1
You need an integral value for accessing a certain element in an array. So, assuming you already have an array <arr> you can do;
x = int(input("Enter index of element: "))
if(x in range(len(arr))):
print(arr[x])
else:
print("Invalid index!")