python - python中的函数定义有问题
问题描述
def prompt(n):
value=int(input("Please enter integer #", n ,":" , sep=""))
return value
value1=prompt(1)
错误:
value=int(input("请输入整数#", n ,":" , sep="")) TypeError: input() 没有关键字参数
解决方案
python中的input()
内置函数只需要1个参数-prompt。输入函数请参考python文档
编辑:根据您的评论,您需要更新提示以包含您发送的参数。请参阅下面的代码。正如评论中提到的 chris,f 字符串仅适用于 Python 3.6 版
def prompt(n):
value=int(input(f"Please enter integer {}".format(n)))
return value
对于 Python 版本 < 3.6,您可以使用旧格式字符串,如下面的代码所示
def prompt(n):
value=int(input("Please enter integer {}".format(n)))
return value
推荐阅读
- java - 当我试图使发布标志 App Bundle 低于错误时
- php - 在 href url 中附加 UTM 参数
- intellij-idea - 运行功能文件时包 cucumber.api.java 不存在
- stm32 - 重新编程STM32F102故障
- python - sympy 拉普拉斯变换函数错误
- json - 在原始 JSON 行中使用值映射
- swift - 向 IOS 应用程序添加“汉堡”菜单
- android - 调试器不工作 android studio 4.2.2
- r - 获取闪亮仪表板正文中的元素列表
- omnet++ - activePacketSource 的 ProductionInterval 不仅随时间变化,而且随生产实体的数量而变化