vba vba -4 years ago 86
Python Question

Get a list of string as input from user in a loop

I am new to python, guess this is a basic question

How do you get a list of string as input from the user? I tried:

array = []
for i in range(0,4):
array[i] = input("Enter string")

This has an error. I know I am wrong. How do we get a list of strings as input?

Answer Source

Your array has size 0, this is why you can't access any elements (or assign to them). The correct code would be:

array = []
for i in range(4):
    array.append(input("Enter string"))
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download