I'm pretty new to python and currently I am working on an income tax calculator and the first step I want the user to do is press 1 if they are married and then press 2 if they are single. What do I need to do to fix this code ? My IDE says there is a syntax error on line 3 "if (answer == 1)"
print ("If you are married press 1 if you are single press 2")
answer = raw_input("")
if (answer == 1)
{
print "Enter your income";
}
elif (answer == 2):
{
print "Enter your income";
}
Python does not use curly braces like most other languages. Instead it uses a colon :
and whitespace to determine blocks. You also do not need (and shouldn't put) semicolons ;
at the end of every line. In addition, you do not need parenthesis around conditions in if/while/etc. statements.This is the correct way to write your code:
print ("If you are married press 1 if you are single press 2")
answer = raw_input("")
if answer == 1:
print "Enter your income"
elif answer == 2:
print "Enter your income"