0

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.

2
  • 1
    return names ? Commented Jan 13, 2020 at 8:21
  • I return it, out of the function to later use it... This might just be an issue of not knowing how to return a list Commented Jan 13, 2020 at 8:23

1 Answer 1

2

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
Sign up to request clarification or add additional context in comments.

7 Comments

When I do that, it says that the variable i wasn't used
@AlexDoiron What ya mean?
When I have the last line as return names
I get an error saying the the "i" in " for i in range" is an unused variable
It said I can only do that in five minutes, I just tried, but I'll try again in a few minutes
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.