[Tutor] Syntax Question

Danny Yoo dyoo at hkn.eecs.berkeley.edu
Thu Sep 11 13:08:07 EDT 2003



On Wed, 10 Sep 2003 Orion72738 at cs.com wrote:

> I am very new to programming, and i am trying to make this program
> convert Fahrenheit to celsius and vice-versa. When I try to run it, I
> get syntax errors.

Hi Orion,



Hello!  Hmmm.... Can you show us the syntax error message?  From what
you've posted:

> ------------------------------------------------------------------------------
> ------------------
> #convert.py
> #   A program to convert Fahrenheit temperatures to Celsius
> ------------------------------------------------------------------------------
> ------------------
>
> def main():
>     Fahrenheit = input("What is the Fahrenheit Temperature?")
>     Celsius = (5.0 / 9.0) * Fahrenheit - 32
>     print "The Temperature is", Celsius, "degrees Celsius."
>
> main()


I actually can't see anything wrong with the code... except potentially
all those minus signs that you used to draw the comment lines! *grin*.

We want to avoid guessing the problem: do a cut-and-paste of the error
message, that SyntaxError, and we'll be able to better understand how to
solve the problem.  Here are a few examples of error messages:


###
>>> 3 + "5"
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
TypeError: unsupported operand types for +: 'int' and 'str'
>>>
>>>
>>> print "hello world
  File "<stdin>", line 1
    print "hello world
                     ^
SyntaxError: invalid token
>>>
>>>
>>> muhahaha
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
NameError: name 'muhahaha' is not defined
###


In each error report, the "traceback" and the error message are both
valuable debugging tools that we can use to put ourselves in Python's
shoes.


Talk to you later!




More information about the Tutor mailing list