0

So I'm fairly new to programming and I'm just paying around trying to make some programs. This one is self-explanatory, but why do I get an invalid syntax for 'print' in line 12 (the first 'elif' statement)?

while True:
    temp = raw_input("Would you like to convert:\nCelsius to Fahrenheit (press 1)\nor\nFahrenheit to Celsius (press 2)\n")

    if temp == 1:
        celsius = raw_input("What is the temperature in degrees Celsius?")
        tempFahr = ((int(celsius)*(9/5))+32)
        print "When it is " + celsius + " degrees celsius, it is " + tempFahr + "degrees fahrenheit."

    elif temp == 2:
        fahrenheit = raw_input("What is the temperature in degrees Fahrenheit?")
        tempCel = ((int(fahrenheit)-32)*(5/9)
        print "When it is " + fahrenheit + " degrees fahrenheit, it is " + tempCel + "degress celsius."

    elif temp = 42:
        print "You're a winner!"

    else:
        print "That is not a valid option."

    print "Press 'enter' to input another value"

    raw_input()

Also, if I over complicated something, I would really appreciate if you could point out what it was. Try not to correct me too much, though, I would like to try and figure it out on my own.

2
  • @jonrsharpe: But the question is tagged with python-2.7 ... Commented Mar 16, 2014 at 18:13
  • @MartinR good point well made... Commented Mar 16, 2014 at 18:16

2 Answers 2

1

There are two syntax errors. First, you forgot a closing ) in the tempCel line, which confuses Python about the next print:

    tempCel = ((int(fahrenheit)-32)*(5/9)
    print "When it is " + fahrenheit + " degrees fahrenheit, it is " + tempCel + "degress celsius."

Then you used = where you meant ==:

elif temp = 42:

There are other errors -- for example, you're comparing temp, which is a string, to 1 and 2, which are integers, and you also might want to type 5/9 at the console to see what it gives you -- but they're not SyntaxErrors.

Sign up to request clarification or add additional context in comments.

2 Comments

Awesome, thanks. I'm going to fix the rest now. I still need to train myself to spot errors like that.
Also thanks for pointing out the floating point problem. Those are a pain in the butt.
0

you should try

        print("When it is " + str(fahrenheit) + " degrees fahrenheit, it is " + str(tempCel) + " degress celsius.")

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.