Python

Well instead of playing with LFS, I have started toying around with Python, and so far I am loving the readability and ease of use. Here is the very basic program I wrote that calculates the perimeter and area of a user defined square. This is only after about 6 hours of reading and playing around so I think I am doing pretty good:


#!/usr/var/python
#filename: flow_control

debug = 0
repeat = 'yes'

print 'This application calculates the perimeter and area of a user defined square.'

if debug == 1:
    print '**begin user data collection function** \n'

while repeat == 'yes':
    width = float (raw_input('\nEnter the measured width: '))
    length = float (raw_input('Enter the measured length: '))

    if debug == 1:
        print '**Begin caculation function** \n'

    perimeter = 2 * (width + length)
    area = (length * width)

    if debug == 1:
        print '**Begin display of calculated measurements** \n'

    print '\nI have calculated the perimeter as:', perimeter
    print 'I have calculated the area as:', area

    repeat = str (raw_input('\nDo you want to try again? Type yes or no. \n'))

else:
        print 'Ok, we are done here. Thanks!'

2 Responses to “Python”

  1. January 4th, 2008 | 12:02 am

    Minor nitpick: your final print line is tabbed over too far :)

    While it won’t break anything in this specific file, tabbing errors like that can bite you later if you were to add more code there :)

  2. RawCode
    January 6th, 2008 | 7:08 am

    Ah, thanks for pointing that out. ;) I played around with tabbing/spacing and python is rather strict about it which is great. So far I am just loving how easy it is to code and the readability when you go back through.