简体   繁体   中英

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM