1

While coding in Python I ran into this error in CMD

Project11.py", line 5
    if Select == 1
                 ^
SyntaxError: invalid syntax

Here is my full program

print("Canadian to USD")

Select = input("Press 1 for Canadian to USD or 2 for USD to Canadian ")

if Select == 1
    Canadian1 = input("Canadian ")

    USD1 = int(Canadian1) * 0.63674
    print("{0}$ = ${1}".format(Canadian1, USD1))

if Select == 2
    USD2 = input("USD ")

    Canadian2 = int(USD2) * 1.5704
    print("${0}={1}$".format(USD2, Canadian2))

Can someone please correct the error or help me please? Thanks :)

5
  • 2
    You are missing a colon (:) at the end of the if line. Commented Aug 1, 2018 at 17:40
  • To expand upon @zvone's comment, you are missing a colon (:) at the end of both if statement lines Commented Aug 1, 2018 at 17:43
  • Either use if Select == '1': or use Select =int(input("Press 1 for Canadian to USD or 2 for USD to Canadian ")). Just putting : isn't sufficient Commented Aug 1, 2018 at 17:45
  • Sorry for not responding I was on vacation when I posted this (evidently Canada lol) and I got so caught up in things that I forgot to check and totally forgot. But I went back to look at this because I had another question on a project and I saw the notification for this and I fixed it and tested it but my results were different from what the internet said so it took me a moment but pretty quickly figured out that it was because of inflation of currencies and whatnot so I fixed it obviously and I was thinking of how it would be pretty neat (continued on next comment) Commented Nov 6, 2018 at 22:10
  • if I also added something so that it would check the internet to make sure it was accurate. I don't know if I'm that invested in this to do that but if someone else wanted to I'd love to see it and again thanks to everyone for the help. ☺ Commented Nov 6, 2018 at 22:10

5 Answers 5

1

You need to put quotes and colons after if Select == "1" and if Select == "2".

So your code would look like:

print("Canadian to USD")

Select = input("Press 1 for Canadian to USD or 2 for USD to Canadian ")

if Select == "1":
    Canadian1 = input("Canadian ")

    USD1 = int(Canadian1) * 0.63674
    print("{0}$ = ${1}".format(Canadian1, USD1))

if Select == "2":
    USD2 = input("USD ")

    Canadian2 = int(USD2) * 1.5704
    print("${0}={1}$".format(USD2, Canadian2))
Sign up to request clarification or add additional context in comments.

2 Comments

Check my comment to the question. You need additional " " around 1 and 2 or you use int(input....)
I fixed it. Thank you.
1

You should use if Select == '1': and if Select == '2': because the input from the keyboard will be a string. You need to either convert it into int or just put ' ' around the string.

Alternatively you can do (also put : after if statement)

Select =int(input("Press 1 for Canadian to USD or 2 for USD to Canadian "))

Comments

1

after that see that input give you a string so you should write:

if Select == "1": 

In order to make it work.

Comments

1

You're missing colons after your if statements.

if int(Select) == 1:

and

if int(Select) == 2:

2 Comments

It won't enter the if statement even if user enters 1 as input because type(Select) will be str
I would delete the first two statements of your answer... The last two are sufficient.
0

The "input method takes a string, so you should set the response to string or transform the input to numbers or boolean. also make sure to add " : " after the if statement

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.