Skip to content
← Back to Community
If/else if/elif syntax error
Profile icon
XplosionCoding

How do you add a string from a previous input command into an if statement without any errors? i think i have tried everything but nothing has worked.

Answered by Codejira [earned 5 cycles]
View Answer
Voters
Profile icon
ZahidHossain1
Profile icon
AndreaGabriela1
Profile icon
SoniaHarley
Profile icon
XplosionCoding
Comments
hotnewtop
Profile icon
Codejira

I don't know if I understand your question, but you can simplify your program beyond recognition :-)
Functions aren't necessary then.

result = 0 while True: print(result) operation = input("add sub mul or div?") operand = float(input("What number? ")) # allow decimals if operation == "add": result += operand # ditto for other operations elif operation == "exit": break # and good practice is: else: print("Bad input!")

Note that the statement to exit a loop is break.

Profile icon
XplosionCoding

@Codejira i just realized what i did wrong with your code. Thank you