1

I'm getting a syntax error on the last line - line 14. I can't see why though, as it seems to be a simple print statement.

cel = "c"
far = "f"
cdegrees = 0
fdegrees = 0
temp_system = input ("Convert to Celsius or Fahrenheit?")
if temp_system == cel:
    cdegrees = input ("How many degrees Fahrenheit to convert to Celsius?")
    output = 5/9 * (fdegrees - 32)
    print "That's " + output + " degrees Celsius!"
elif temp_system == far:
    fdegrees = input ("How many degrees Celsius to convert to Fahrenheit?")
    output = (32 - 5/9) / cdegrees
    print "That's " + output + " degrees Fahrenheit!"
else print "I'm not following your banter old chap. Please try again."
1
  • 5
    Please always include the complete traceback of the error. Commented Apr 12, 2012 at 15:28

1 Answer 1

9

You forgot the colon (:) after the last else.

Also:

input ("Convert to Celsius or Fahrenheit?")

should be changed to

raw_input ("Convert to Celsius or Fahrenheit?")

as input() tries to evaluate its input while raw_input takes a 'raw' string. When you enter c for example into the input() it tries to evaluate the expression c as if it were python code which looks for a variable c whereas raw_input simply takes the string without attempting to evaluate it.

Also you cannot concatenate(add together) strings with integers as you are doing in this case where output is a number.

Change it to

print "That's " + str(output) + " degrees Celsius!"

or

print "That's %d degrees Celsius!" % output
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks - I didn't realize the : was optional. I'm still getting errors in this simple program though. I want to pick celsius so after the first input prompt I enter: c. Traceback (most recent call last): File "<stdin>", line 5, in <module> File "<string>", line 1, in <module> NameError: name 'c' is not defined Didn't I define this at the start?
Thank you! I've learned about 4 things from this one answer. :)
No problem. I'm surprised nobody wrote it out before me but everyone just assumed it was the one else statement.

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.