Here is a simple program that can average a list of numbers. I wrote this to introduce someone to the language that we all use and love. :D The program may be simple, but it shows how easily a simple but useful program can turn out to be.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
def main(): while True: try: string = raw_input('What numbers should I average? ') words = string.split() numbers = map(float, words) average = sum(numbers) / len(numbers) print 'The average is', average raw_input('Press enter to quit.\n') return except: print 'ERROR: I can only take numbers!' if __name__ == '__main__': main()
Want to introduce someone to Python? You might want to try this program. It is simple and should not be that difficult to understand. It might be a bit more than a "Hello World" program, but at least this one will do something useful.