我试图将所有输入添加到另一个函数中,然后返回到main,但得到了错误:Can't convert 'int' object to str implicitly
。你知道吗
这是我的密码:
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()
在第13行和第14行,将数字和字符串(
'\n'
)与+
运算符组合。+
在两个操作数都是数字或都是字符串时工作,但不能混合和匹配。在连接片段之前,用str()
将数字转换为字符串。你知道吗用
str(
+)
环绕输入。然后,当您想使用其他函数时,更改要用int(
+)
包装的函数中的参数相关问题 更多 >
编程相关推荐