python - 值错误: int() 的无效文字无效文字,基数为 10:3,5
问题描述
这应该是我的输出
输入您的选择:3
输入底数,后跟指数:5 3 5
的幂次方为 3 是 125。
n,exp=int(input("Enter the value of the base followed by the exponent:")).split(",")
def power(n,exp):
if(exp==1):
return(n)
if(exp!=1):
return(n*power(n,exp-1))
print("The power of",n, "raised to",exp,"is",power(n,exp))
解决方案
您无法转换5, 3
为 int。首先将其拆分并将结果转换为 int
n, exp = [int(x) for x in input("Enter the value of the base followed by the exponent:").split(",")]
您还应该避免对全局和函数使用相同的变量名称。
推荐阅读
- python - 创建以调用者脚本文件名命名的日志文件
- c# - 不同控制器中的 OData 自定义路由约定
- swift - 我在哪里从 UIAlertController 的选择中重新加载 tableView?
- python - 在 read_csv() 中忽略的 Pandas 类别 dtypes
- python-3.x - 将多个数据框转换为带有标题的 HTML 页面
- javascript - 在给定条件下修改 JavaScript 中的树结构数据?
- firebase - 如何让登录用户安全连接到数据库?智威汤逊?
- python - 如何在套接字编程python中获取用户PC名称
- xcode - XCODE吊销证书后,Codesign想使用XXX钥匙串
- ibm-integration-bus - 在 IIB 中使用 UDP 中的字段引用