Alex Doiron
Alex Doiron

Reputation: 13

How do I create a list from the input of a user? w/Python

I've been trying to make a function that uses a number previously determined from another function (which I have that part of the code working) and asks the user to give an amount of names equal to the number previously determined. Here's the code:

def getNames(myNumOfTypes):
    print("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")
    print("Now, enter all the names of the people getting a type:")

    names = []
    for i in range(0, myNumOfTypes):
        name = input("-")
        names.append(name)
    return names[i]

Later, when I print the names list, it's only a list of the last input I entered... I never really learned for loops and lists, and now I'm trying to use both and it's rough. for reference, myNumOfTypes was a variable I used earlier, but because the numbers have to be the same I just recycled it.

Upvotes: 0

Views: 56

Answers (1)

U13-Forward
U13-Forward

Reputation: 71580

You added a [i] on the last line which gets the value of a specific index, you need to remove it to make the last line become:

    return names

Upvotes: 2

Related Questions