[Tutor] Syntax error help

bob gailer bgailer at gmail.com
Fri Mar 30 23:30:22 CEST 2012


On 3/30/2012 4:26 PM, chris knarvik wrote:
> Alright i have been trying to right a (relatively) simple to calculate 
> area and volume below is my current working code

Suggestion: start with a VERY SIMPLE program and get that working. Then 
add one new feature at a time.

Is the following in Area.py? If it is then the traceback could not have 
come from importing this code, because line 10 does not mention areamenu().
In fact areamenu() appears ONLY in line 1, but not by itself!

> def areamenu():
>     print 'Square (1)'
>     print 'triangle (2)'
>     print 'rectangle (3)'
>     print 'trapazoid (4)'
>     print 'circle (5)'
>
> def squareacalc():
>     sidelength = input('enter side length: ')
>     print ' the side length is' sidelength ** 2
>
> def displaymenu():
>     print 'please make a selection';
>     print 'Area (1)';
>     choice = input(raw_input('enter selection number'):
>     if (choice == 1):
>         Areamenu():
>
>     else:
>         print 'choice' , choice, ' is wrong try again'
>
> def selctiona():
>     Areamenu();
>     choicea = input(raw_input'enter selection');
>     if (choicea == 1):
>         squareacalc()
>
>
>
>  print 'good bye'
>
> I keep getting this error
> Traceback (most recent call last):
>   File "<pyshell#3>", line 1, in <module>
>     import Area
>   File "C:\Python27\Area.py", line 10
>     areamenu()
>            ^
> SyntaxError: invalid syntax
>
> can anyone tell me what im doing wrong i cant see the problem
> help would be appreciated
>
What are you using to run the above? I'll guess the interactive window 
of IDLE. Try reload(Area). Once a module is imported you must reload to 
import it again. (I am assuming you made changes after the initial error.)

The above code should give you something like:
Traceback (most recent call last):
   File "<interactive input>", line 1, in <module>
   File "Script3.py", line 10
     print ' the side length is' sidelength ** 2
                                          ^
SyntaxError: invalid syntax

fix that (do you know what to do?) then you should get a syntax error 
for line15. Why is there a : at the end of that line?
then you have 1 more trailing : to deal with.
then there is a missing )
then there is a missing (

Once you fix all the problems then you should see
good bye
since that is the only executable code in Area.py other than def statements.

Suggestion: start with a VERY SIMPLE program and get that working. Then 
add one new feature at a time.

-- 
Bob Gailer
919-636-4239
Chapel Hill NC



More information about the Tutor mailing list