Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/335.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Can';t转换为';int';对象到str隐式模块化python_Python - Fatal编程技术网

Can';t转换为';int';对象到str隐式模块化python

Can';t转换为';int';对象到str隐式模块化python,python,Python,我试图将所有输入添加到另一个函数中,然后返回到main,但我得到了错误:无法将“int”对象隐式转换为str 这是我的密码: 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

我试图将所有输入添加到另一个函数中,然后返回到main,但我得到了错误:
无法将“int”对象隐式转换为str

这是我的密码:

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(
+

进行包装。我实际上刚刚去掉了字符串。我现在唯一的问题是它何时进入输出txt文件。与其添加数字,不如像“3456789”这样并排放置,请显示传递给任何
文件的参数。write()
calls.2016年5月1500 800 120 110 45 95 550 15008001201104595550 150080012011045955508001201104595550800120459555015008001201104595550800120110459555015001201104595550800120110459555080012045955508001201104595550150012011045955508001204595550800110459555080011045955508001201109555080011045955508001201109555080011045955508001201109555080012095550110955508001104595550800120110550800110955501109555011095550800120955501109555011095550