Home>

I'm a novice in Python, and I wanted to make a calculator. I got out a mistake: Print ("Amount -" + Str (Answer))

Syntaxerror: Invalid Syntax

Here is its code:

first_number= int (Input ("Enter the number"))
Second_Number= INT (Input ("Enter the second number"))
ACT= INPUT ("Enter the action symbol (+ -folded, --deduct, * -multiply, /-split")
IF Act== "+":
    Try:
     Answer= first_number + Second_Number
    Print ("Amount -" + Str (Answer))
IF Act== "-":
    Try:
     Answer= First_Number -Second_Number
    Print ("Difference -" + Str (Answer))
    IF ACT== "*":
    Try:
     Answer= first_number * Second_Number
    Print ("Work -" + Str (Answer))
IF Act== "/":
    Try:
     Answer= first_number /Second_Number
    Except Zerodivisionerror:
     Answer= "To divide to zero!"
    PRINT (ANSWER)

Observe gaps and tabs .....

entithat2021-05-04 15:15:23

Also does not happen try without except

insolor2021-05-04 15:29:29

Yes, here because of the lack of Except: obviously an error

CrazyElf2021-05-04 15:35:58
  • Answer # 1

    try is a function that is related to Except, you cannot simply write try ... and do not write an exception, therefore an error occurs in the syntax. If you do not need to write anything in case of error you can write: Try: #Code. Except: Pass #Pass is a function that does not do anything (just fills the place)

    can be without Pass, the main thing is that something has been performed there

    Yes, and try, except for the fission errors on zero it is not needed there, you can remove it and nothing will change

    NoName2021-05-04 17:03:52

    Thank you!! Help! Now starts!

    Степан2021-05-04 17:52:40
  • Answer # 2

    try is a function that is related to Except, you cannot simply write try ... and do not write an exception, therefore an error occurs in the syntax. If you do not need to write anything in case of error you can write: Try: #Code. Except: Pass #Pass is a function that does not do anything (just fills the place)

    can be without Pass, the main thing is that something has been performed there

    Yes, and try, except for the fission errors on zero it is not needed there, you can remove it and nothing will change

    NoName2021-05-04 17:03:52

    Thank you!! Help! Now starts!

    Степан2021-05-04 17:52:40