[Tutor] why do i keep getting syntax errors in python when this runs

Alan Gauld alan.gauld at btinternet.com
Sat Sep 7 01:31:30 CEST 2013


On 06/09/13 05:27, mike johnson wrote:
> can you please help me figure out why this isnt working thanks

The fundamental problem is that Python is case sensitive
so Def and def are two different words.
As are Main and main and Print and print.

Also Python cares about spacing. You need to indent your
code within the function.

> Def main ():
> Celsius = float (input ("What is the Celsius temperature? "))
> Fahrenheit = 9.0 / 5.0 * Celsius + 32
> Print ("The temperature is ", Fahrenheit, " degrees Fahrenheit.")
 >
 > Main()

Finally, as a matter of style, capitalized names tend to be
reserved for class definitions (you probably haven't read
about them yet!)

This should therefore become:

def main ():
    celsius = float (input ("What is the Celsius temperature? "))
    fahrenheit = 9.0 / 5.0 * celsius + 32
    print ("The temperature is ", fahrenheit, " degrees Fahrenheit.")

main()

HTH

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/



More information about the Tutor mailing list