def numArrayElements():
num = int(input("please enter a number "))
return num
numArrayElements()
def inputArray():
num = numArrayElements()
myArray = []
for i in range(0,num):
numlis = int(input("please enter a number "))
myArray.append(numlis)
return myArray
inputArray()
def printArray():
print(myArray)
printArray()
Asked
Active
Viewed 30 times
-2

khelwood
- 55,782
- 14
- 81
- 108
-
2You should familiarize yourself with the concept of scope. If you search for "python scope" there will be a number of resources to aid you in understanding. – R. Arctor Oct 13 '20 at 18:36
-
Does this answer your question? [Short description of the scoping rules?](https://stackoverflow.com/questions/291978/short-description-of-the-scoping-rules) – Pranav Hosangadi Oct 13 '20 at 18:39
1 Answers
0
its need to use arguments with functions :
def numArrayElements():
num = int(input("please enter a number "))
return num
def inputArray(num):
myArray = []
for i in range(0,num):
numlis = int(input("please enter a number: "))
myArray.append(numlis)
return myArray
def printArray(myArray):
print(myArray)
num = numArrayElements()
arr = inputArray(num)
printArray(arr)
your get outs:
please enter a number 3
please enter a number: 1
please enter a number: 3
please enter a number: 2
[1, 3, 2]

Timur U
- 415
- 2
- 14