繁体   English   中英

Python 3.3程序无法正常工作?

[英]Python 3.3 programs not working?

我现在已经用Python编写了一些程序,但是我还是很新。 我已经更新到3.3,并且我的大多数程序都已损坏。 我现在已经用input替换了所有raw_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

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

print("The answer is:", AddAnswer)

print("The answer is:", MulAnswer)

等等

在哪里构建字符串,在print()函数中这样做会更容易。 代替

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

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

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

等等其他选项。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM