简体   繁体   中英

Python 3.3 programs not working?

I've made a few programs in Python now, but I'm still pretty new. I've updated to 3.3, and most of my programs are broken. I've replaced all of the raw_input s now with input , but this still isn't working, and I get no errors.

Could one of you fine programmers help?

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

Put all items you want to print in the parenthesis of the print() function call:

print("The answer is:", AddAnswer)

and

print("The answer is:", MulAnswer)

etc.

Where you build your strings, it'd be easier to do so in the print() function. Instead of

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

(where you forgot to replace the last comma with + ), do this:

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

and so on for the other options.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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