XMaster65
XMaster65

Reputation: 33

Python CMD Syntax error

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 :)

Upvotes: 1

Views: 295

Answers (5)

pointneo
pointneo

Reputation: 11

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

Upvotes: 0

ltd9938
ltd9938

Reputation: 1454

You're missing colons after your if statements.

if int(Select) == 1:

and

if int(Select) == 2:

Upvotes: 1

Trooper Z
Trooper Z

Reputation: 1661

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))

Upvotes: 1

user10145827
user10145827

Reputation: 11

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

if Select == "1": 

In order to make it work.

Upvotes: 1

Sheldore
Sheldore

Reputation: 39072

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 "))

Upvotes: 1

Related Questions