0

现在我的代码有点纠结。代码:

def main(a,b):
    c=a+b
    print("Your answer was: %s"% c)
    input()

def launch():
    print("Please set integer a and integer b!")
    intA=input("Integer A: ")
    intB=input("Integer B: ")
    input("Press return to continue!")
    main(intA, intB)

我需要帮助的是将 intA&intB 转换为 ACTUAL 整数。因为当我运行这段代码时,我得到:3030 ...如果有人能提供帮助,我将不胜感激!谢谢!:)

4

2 回答 2

1

改变

intA=input("Integer A: ")
intB=input("Integer B: ")

intA=int(input("Integer A: "))
intB=int(input("Integer B: "))
于 2013-04-14T21:55:02.753 回答
0

您可以使用int

c = int(a)+int(b)

当然,您甚至可以在调用 main 方法之前进行此转换。

关键是:int尝试将参数转换为整数,相反,您可以使用str将数字转换为字符串。

于 2013-04-14T21:54:52.827 回答