Search code examples
pythonfunction-definition

Having problems with function definition in python


def prompt(n):
    value=int(input("Please enter integer #", n ,":" , sep=""))
    return value

value1=prompt(1)

error:

value=int(input("Please enter integer #", n ,":" , sep="")) TypeError: input() takes no keyword arguments


Solution

  • The input() built-in function in python takes only 1 parameter - prompt. Please refer to the python documentation for input function

    Edit: As per your comment, you need to update your prompt to include the parameter that you've sent. See the code below. As chris mentioned in the comments, the f-strings will work only in Python versions 3.6

    def prompt(n): 
        value=int(input(f"Please enter integer {}".format(n))) 
        return value
    

    For Python versions < 3.6, you can you use the old formatting strings as shown in the code below

    def prompt(n): 
        value=int(input("Please enter integer {}".format(n))) 
        return value