0

I am wondering, is there a way to use the input() function inside a user-defined function? I tried doing this

def  nameEdit(name):
    name = input()
    name = name.capitalize
    return name
1
  • 1
    And...? Does it give an error? Commented Jun 4, 2014 at 19:27

2 Answers 2

2

Using input is fine. However, you aren't calling name.capitalize; you're just getting a reference to the method and assigning that to name. [Further, as pointed out by Bob, your function doesn't need a name argument.] The correct code would be

def nameEdit():
    name = input()
    name = name.capitalize()
    return name

or more simply:

def nameEdit():
    return input().capitalize()
Sign up to request clarification or add additional context in comments.

1 Comment

There shouldn't be a need to pass in a name argument to the method since it isn't actually being used. Unless I'm missing something.
1

Are you talking about asking for input from a user from a method? If so then this would be what you're looking for:

def nameEdit():
    name = input("Enter your name: ")
    name = name.capitalize()
    return name

3 Comments

The tags say Python 3, so it'd be input instead of raw_input.
Also, that won't run until you call the function. nameEdit()
Thanks for the catch on the raw_input, forgot about that. Updated my answer accordingly.

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.