I need to create a list with a length determined by a user input.
How would I do this?
Example: If the user inputs 3 I need a list with 3 indexes.
I need to create a list with a length determined by a user input.
How would I do this?
Example: If the user inputs 3 I need a list with 3 indexes.
What do you want to fill the list with? If you just want a list with n indexes:
n = user_input_length
list = [None for x in range(n)]
None
is immutable (moreover it is a singletone); you could use your_list = [None] * n
(don't use list
as a name; it shadows the builtin).
You can take in input, then populate your list:
import random
num = int(input('How long do you want the list? ')) #5
lst = [random.randint(1, 10) for i in range(num)]
print lst #[6, 1, 2, 1, 8]