Python 3.3程序不起作用?

时间:2013-12-06 16:32:16

标签: python python-3.3

我现在用Python制作了一些程序,但我还是很新的。我已经更新到3.3了,我的大部分程序都坏了。我已经用raw_input替换了所有input,但这仍然无效,我没有错误。

你们这些优秀的程序员能帮忙吗?

a = 1
while a < 10:
    StartQ = input("Would you like to Start the program, or Exit it?\n")
    if StartQ == "Exit":
        break
    elif StartQ == "Start":
        AMSoD = input("Would you like to Add, Multiply, Subtract or Divide?\nPlease enter A, M, S or D.\n")
        if AMSoD == "A":
            Add1 = input("Add this: ")
            Add2 = input("By this: ")
            AddAnswer = int(Add1) + int(Add2)
            AAnswer = Add1 + " " + "+" + " " + Add2 + " " + "=",AddAnswer
            print(AAnswer)
            print("The answer is:"),AddAnswer
        elif AMSoD == "M":
            Mul1 = input("Multiply this: ")
            Mul2 = input("By this: ")
            MulAnswer = int(Mul1) * int(Mul2)
            MAnswer = Mul1 + " " + "*" + " " + Mul2 + " " + "=",MulAnswer
            print(MAnswer)
            print("The answer is:"), (MulAnswer)
        elif AMSoD == "S":
            Sub1 = input("Subtract this: ")
            Sub2 = input("From this: ")
            SubAnswer = int(Sub2) - int(Sub1)
            SAnswer = Sub2 + " " + "-" + " " + Sub1 + " " + "=",SubAnswer
            print(SAnswer)
            print("The answer is:"), (SubAnswer)
        elif AMSoD == "D":
            Div1 = input("Divide this: ")
            Div2 = input("By this: ")
            DivAnswer = int(Div1) / int(Div2)
            DAnswer = Div1 + " " + "/" + " " + Div2 + " " + "=",DivAnswer
            print(DAnswer)
            print("The answer is:"), (DivAnswer)
            DivQoR = input("Would you like to Quit or restart?\nAnswer Quit or Restart.\n")
            if DivQoR == "Restart":
                a = 1
            elif DivQoR == "Quit":
                DivQoRAyS = input("Are you sure you want to quit? Answer Yes or No.\n")
                if DivQoRAyS == "Yes":
                    break
                elif DivQoRAyS == "No":
                    a = 1

1 个答案:

答案 0 :(得分:3)

要打印的所有项目放在print()函数调用的括号中:

print("The answer is:", AddAnswer)

print("The answer is:", MulAnswer)

在构建字符串的地方,print()函数更容易实现。而不是

AAnswer = Add1 + " " + "+" + " " + Add2 + " " + "=",AddAnswer
print(AAnswer)

(忘记用+替换最后一个逗号),请执行以下操作:

print(Add1, '+', Add2, '=', AddAnswer)

等等其他选项。