[Tutor] What's the invalid synax? Error message and code supplied.

Nathan Pinno falcon3166 at hotmail.com
Sun Jul 31 00:19:30 CEST 2005


Here's the message:
  File "D:\Python22\prog4.py", line 19
    while option != 9:
        ^
SyntaxError: invalid syntax

And the code:
#This program finds the area and perimeter of circles, rectangles, and squares.
def menu():
    print '1) Area (Circle)'
    print '2) Area (Rectangle)'
    print '3) Area (Square)'
    print '4) Perimeter (Circle)'
    print '5) Perimeter (Square)'
    print '6) Perimeter (Rectangle)'
    print '9) Exit'

import math
print 'By Nathan Pinno'
print 'ID# 2413448'
print
print 'Program 4 - Functions'
print
menu()
option = int(raw_input('Option (1,2,3,4,5,6,9): ')
while option != 9:
    if option == 1:
        r = int(raw_input('Radius: ')
        print 'The area of the circle = ',pi*(r**2)
        option = int(raw_input('Option (1,2,3,4,5,6,9): ')
    elif option == 2:
        l = int(raw_input('Length: ')
        w = int(raw_input('Width: ')
        print 'The area of the rectangle = ',l*w
        option = int(raw_input('Option (1,2,3,4,5,6,9): ')
    elif option == 3:
        s = int(raw_input('Side: ')
        print 'The area of a square = ',s**2
        option = int(raw_input('Option (1,2,3,4,5,6,9): ')
    elif option == 4:
        d = int(raw_input('Diameter: ')
        print 'The perimeter of the circle = ',pi*d
        option = int(raw_input('Option (1,2,3,4,5,6,9): ')
    elif option == 5:
        l = int(raw_input('Length: ')
        w = int(raw_input('Width: ')
        print 'The perimeter of the rectangle = ',(2*l)+(2*w)
        option = int(raw_input('Option (1,2,3,4,5,6,9): ')
    elif option == 6:
        s = int(raw_input('Side: ')
        print 'The perimeter of a square = ',s*4
        option = int(raw_input('Option (1,2,3,4,5,6,9): ')
    else:
        print 'That is not an option. Please choose an option.'
        option = int(raw_input('Option (1,2,3,4,5,6,9): ')
print 'Goodbye.'
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20050730/0734224a/attachment-0001.htm


More information about the Tutor mailing list