Python中文
首页
教程
问答
标签
搜索
登录
注册
无法将“int”对象隐式转换为str模块化python
回答此问题可获得
20
贡献值,回答如果被采纳可获得
50
分。
<p>我试图将所有输入添加到另一个函数中,然后返回到main,但得到了错误:<code>Can't convert 'int' object to str implicitly</code>。你知道吗</p> <p>这是我的密码:</p> <pre><code>def main(): input1 = input("Enter the month: ") input2 = input("Enter the year: ") input3 = input("Enter the home mortgage payment amount: ") input4 = input("Enter the car payment amount: ") input5 = input("Enter the gas payment amount: ") input6 = input("Enter the electric payment amount: ") input7 = input("Enter the phone payment amount: ") input8 = input("Enter the cell payment maount: ") input9 = input("Enter the miscellaneous payment amount: ") monpay = calcMonthlyPay(input3,input4,input5,input6,input7,input8,input9) yearpay = calcYearlyPay(monpay) print("SUCCESS: Data wrtten to the may.txt file") file = open("may.txt", "w") file.write(input1 + "\n" + input2 + "\n" + input3 + "\n" + input4 + "\n") file.write(input5 + "\n" + input6 + "\n" + input7 + "\n" + input8 + "\n" + input9 + "\n") file.write(monpay + "\n") file.write(yearpay) file.close() def calcMonthlyPay(input3,input4,input5,input6,input7,input8,input9): monthpay = (input3+input4+input5+input6+input7+input8+input9) return monthpay def calcYearlyPay(monpay): yearpay = monpay * 12 return yearpay main() </code></pre>
0 条评论
分类:
Python问答
请先
登录
后评论
默认排序
时间排序
1 个回答
匿名
1天前
擅长:python、mysql、java
<p>在第13行和第14行,将数字和字符串(<code>'\n'</code>)与<code>+</code>运算符组合。<code>+</code>在两个操作数都是数字或都是字符串时工作,但不能混合和匹配。在连接片段之前,用<code>str()</code>将数字转换为字符串。你知道吗</p>
请先
登录
后评论
针对此问题:
更多的回答
关注
89
关注
收藏
1
收藏,
216
浏览
网友 提问于 2天前
相关Python问题
如何在python中从数据帧列中删除分类值?
8 回答
如何在python中从数据帧列表中删除引号
2 回答
如何在python中从数据帧创建列表
5 回答
如何在Python中从数据帧创建嵌套的JSON
1 回答
如何在Python中从数据帧显示wordcloud
2 回答
如何在Python中从数据帧的时间戳中删除字符
6 回答
如何在Python中从数据帧绘制简单绘图?
5 回答
如何在python中从数据帧行提取具有特定长度的范围?
8 回答
如何在python中从数据帧设置dict中的值
1 回答
如何在Python中从数据库中获得一个结果
4 回答
如何在python中从数据框中绘制分类条形图
10 回答
如何在Python中从数据框中选择特定细节?
7 回答
如何在python中从数据集中删除unicode
1 回答
如何在python中从数据集中删除某些数值?
9 回答
如何在python中从数据集中选择行
9 回答
如何在Python中从数组中删除元素
5 回答
如何在python中从数组中删除单个倒逗号?
10 回答
如何在python中从数组中删除对象?
2 回答
如何在python中从数组中删除引号
10 回答
如何在python中从数组中删除所有最小值
2 回答